0

I am new to AMPscript and trying to create a form that will find and update our subscribers or create new ones inside of SFDC but have run into some issues.

Goal of form: Collect Subscriber Key from URL and find or create lead.

Current issue: AMPscript is not updating the lead but only creating new ones.

I have set my code to detect the subscriber key and submit at the lead id. When I visit the landing page without an subscriber passed URL I receive the "Missing Subscriber Key" pop up instead of the form. But when I test through an subscriber, the form populates, once a form is submitted it creates a new lead and disregards the update set.

Can you help me identify why this may be happening?


%%[
var @Id, @firstName, @lastName, @email, @subscriberRows, @subscriberRow
set @Id = _Subscriberkey

if (@Id != "") then

IF RequestParameter("submitted") == true THEN

  SET @subscriberRows = RetrieveSalesforceObjects(
   "Lead",
   "Id,Email, FirstName, LastName",
   "Id", "=", RequestParameter("@Id")
   )

  IF RowCount(@subscriberRows) > 0 THEN 
  SET @leadId = Field(Row(@subscriberRows, 1), "Id")

  SET @updateRecord = UpdateSingleSalesforceObject(
      "Lead", @Id,
      "FirstName", RequestParameter("firstname"),
      "LastName", RequestParameter("lastname"),
      "Company", RequestParameter("company"),
      "Email", RequestParameter("email"),
      "LeadSource", RequestParameter("LeadSource"),
      "Distribution", RequestParameter("Distribution__c")
     )

  ELSE

  SET @leadId = CreateSalesforceObject(
        "Lead", 6,
        "FirstName", RequestParameter("firstname"),
        "LastName", RequestParameter("lastname"),
        "Company", RequestParameter("company"),
        "Email", RequestParameter("email"),
        "LeadSource", RequestParameter("LeadSource"),
        "Distribution__c", RequestParameter("Distribution__c")
       )
  ENDIF   
]%% 

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

%%[ ELSE ]%%

<table style="padding: 20px;"><tr><td>
      <h2>Update your menu:</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="Subscriber Key" type="hidden" value="%%=v(@id)=%%"><br>
         <input name="LeadSource" type="hidden" value="Tester"><br>
         <input name="Distribution__c" type="hidden" value="INTERNAL"><br>
         <input name="submitted" type="hidden" value="TRUE"><br>
         <input type="submit" value="Submit">
      </form>  
</td></tr></table>

%%[ ENDIF 

else]%%

Missing subscriber key.

%%[endif]%%
4
  • I believe your issue is this line "Id", "=", RequestParameter("@Id") . it should simply be "Id", "=", @id
    – EazyE
    Jan 27, 2020 at 17:14
  • @EazyE I've attempted to make that change but once I press submit, the page breaks and sends a 500 error
    – Egypte
    Jan 27, 2020 at 17:35
  • @EazyE you were correct. I attempted once more by removing the RequestParameter and fixing "set leadid" to "set result" and it works perfectly now. Thanks!
    – Egypte
    Jan 27, 2020 at 18:07
  • I'll add my comment as an answer to marked as correct
    – EazyE
    Jan 27, 2020 at 20:36

1 Answer 1

1

You need to update your code to the following:

SET @subscriberRows = RetrieveSalesforceObjects(
   "Lead",
   "Id,Email, FirstName, LastName",
   "Id", "=", @Id)
   )

You must log in to answer this question.

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