I have a form that after being filled in creates a data extension record. Based on data from that form I would like to trigger automation that would take an email provided in a form/DE, and check if a Contact/Person Account with that email address already exists in Sales Cloud.

If the record exists in Sales Cloud - update it with fields from Data Extension.

If the record doesn't exist in Sales Cloud - create a new record based on data provided.

Is it possible with the use of AMPscript in Automation Studio? Or maybe there is some other way to do this?


1 Answer 1


There’s a much easier way to do this directly from the form.

You can use the code below to create a form on a CloudPgae that will capture basic info of the visitor, and upon submission, it will check if a person with this email address exists in Salesforce CRM. If the person exists, their info will get updated. If not, a new lead will be created. It also writes the details of the form submission into a DE.


IF RequestParameter("submitted") == true THEN

/* check if lead already exists */

  SET @subscriberRows = RetrieveSalesforceObjects(



   "Email", "=", RequestParameter("email")



  /* get lead id if lead exists */


  IF RowCount(@subscriberRows) > 0 THEN 

  SET @leadId = Field(Row(@subscriberRows, 1), "Id")


  /* update existing lead */

  SET @updateRecord = UpdateSingleSalesforceObject(

      "Lead", @leadId,

      "FirstName", RequestParameter("firstname"),

      "LastName", RequestParameter("lastname"),

      "Company", RequestParameter("company")


  /* add lead details to a DE */

  InsertData("DataExtensionName","LeadId", @leadId)


   /* create a new lead */

  SET @leadId = CreateSalesforceObject(

        "Lead", 4,

        "FirstName", RequestParameter("firstname"),

        "LastName", RequestParameter("lastname"),

        "Company", RequestParameter("company"),

        "Email", RequestParameter("email")




<h2>Thank you for submitting the form.</h2>

%%[ ELSE ]%%

<table style="padding: 20px;"><tr><td>

      <h2>Please fill in the form:</h2>

      <form action="%%=RequestParameter('PAGEURL')=%%" method="post">

         <label>First name: </label><input type="text" name="firstname" required=""><br>

         <label>Last name: </label><input type="text" name="lastname" required=""><br>

         <label>Company: </label><input type="text" name="company" required=""><br>

         <label>Email: </label><input type="text" name="email" required=""><br>

         <input name="submitted" type="hidden" value="true"><br>

         <input type="submit" value="Submit">



%%[ ENDIF ]%%

You can adjust above script to your needs (to check and update/create a contact instead of a lead) or extend it if you need it to do more, eg. add the lead/contact to a Salesforce campaign or send them an email. Read more here: Create a Sales Cloud-integrated lead capture form using AMPscript

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .