I am trying to create a landing page in cloud page to be reached by a link in an email previously sent by a Marketing cloud Journey. The pages I built must:

  • Get the email address from the email with the link clicked (request parameter)
  • Retrieve the Service Cloud account records having that email (which can be more than one records)
  • Update a custom field related to the Service Cloud account records retrieved above (since those records can be more than one I use a “for to do” AMPscript function) The AMPscript i used is the following

var @AccountRows, @i, @RowCount

SET @email = RequestParameter("email")

set @AccountRows = RetrieveSalesforceObjects("Account", "Id", "Email__c", "=", @email )

set @RowCount = RowCount(@AccountRows)

if @RowCount > 0 

  then for @i = 1 to @RowCount do

           var @AccountRow, @AccountId, @result

           set @AccountRow = Row(@AccountRows, @i)

           set @AccountId = Field(@AccountRow, "Id")

           Output(Concat("AccountId: ", @AccountId))

           set @result = UpdateSingleSalesforceObject("Account", @AccountId, "BlacklistDEM__c", "True")

       next @RowCount



The problem I had with that AMPscript is that I cannot successfully publish the page (or it seems I could but when I Access the page I get this error:

Server error 500 - Internal server error. There is a problem with the resource you are looking for, and it cannot be displayed

Even the preview of the page does not work (it starts and never ends). Can anyone help me understand what is wrong with my AMPscript and how it should be in order to get what I described above?

  • 1
    If you comment out your UpdateSingleSalesforceObject line, what happens? Jul 6, 2020 at 21:30
  • Please update your question to include some details about how subscribers are arriving at this page. How are you formulating that link? Jul 6, 2020 at 21:32
  • I'd add some error checking after retrieving the email address to ensure it has a value before calling RetrieveSalesforceObjects. That's probably why your preview runs forever. Also maybe try removing the Output() call. I never have luck with those. Jul 6, 2020 at 22:44
  • Hi Adam, thanks for your reply, if I comment out UpdateSingleSalesforceObject line I can publish the page e se the preview. Subscribers arrives at the page through a link in an email, cloud.email.carrefour.it/LeadUnsubscribe?email=%%EmailAddress%% Jul 7, 2020 at 0:26
  • Hi Sam, thanks for your reply, can you please write me the ampscript you made to do your check? What I have notice is that when preview the page since there is not an email addresses to be used to retrieve the Service cloud Account records, the page seems to load all Account records ... that's probably why the preview runs forever. Then just for a test If I replay a fixed number in the for loop instead of @RowCount, it also works... but of course the number of account records varies depending on how many accounts has the same email... Is there any trick to avoid it? Jul 7, 2020 at 0:40

1 Answer 1


You have an error in your for loop. NEXT @RowCount must be NEXT @i as you want to increase @i not @RowCount.

Also, you may consider to replace or not allow any ' character in the email input as this can cause your RetrieveSalesforceObjects to fail as well as per this ticket: https://trailblazer.salesforce.com/issues_view?id=a1p3A000000AUAbQAO


You should re-think this approach completely as you have no validation that the call of the page is coming from an email as expected. With this setup I would be able to run a list of emails against your endpoint and update your CRM records.

A better approach would be using CloudPageURL and adding QueryStringParameters to the call and at least expect a payload which you set in the link of the email.

Here is your code adjusted:

    VAR @AccountRows, @i, @RowCount

    SET @email = replace(RequestParameter("email"), "'", "")
    SET @key = RequestParameter("key")

    IF NOT Empty(@email) AND @key == 'yourKeyYouDefineInTheEmail' THEN

        SET @AccountRows = RetrieveSalesforceObjects("Account", "Id", "Email__c", "=", @email )

        SET @RowCount = RowCount(@AccountRows)

        IF @RowCount > 0 THEN 
            FOR @i = 1 TO @RowCount DO

                VAR @AccountId, @result

                SET @AccountId = Field(Row(@AccountRows, @i), "Id")

                IF NOT Empty(@AccountId) THEN
                    UpdateSingleSalesforceObject("Account", @AccountId, "BlacklistDEM__c", "True")

            NEXT @i



In your email:

    CloudPageURL('ID of your cloudpage','email',emailaddr,'key','yourKeyYouDefineInTheEmail')

You must log in to answer this question.

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