0

This same code is working for contact but when i use this function to update a field on Lead object, the preview for the CloudPage is not coming. When i remove this function from the cloud page it starts showing up the preview. Something is wrong but not able figure out. Below is the code :

%%[
var @resultLead
Set @rsLead= RetrieveSalesforceObjects('Lead', 'Id', 'Email', '=', '[email protected]')

Set @countLead = rowcount(@rsLead)

outputline(concat('Number of leads', @countLead))

IF @countLead > 0 THEN

    for @i = 1 to @countLead do

    SET @LeadRow = Row(@rsLead,@i)   
    SET @LeadID = Field(@LeadRow ,'Id') 
    SET @resultLead = UpdateSingleSalesforceObject('Lead',@LeadID,'HasOptedOutOfEmail','True')

    OutputLine(concat('LeadID', @resultLead))
    next @i

ENDIF
]%% 

1 Answer 1

0

I'd make sure you have a @leadID before running the update:

%%[

var @rsLead, @countLead, @i, @leadRow, @leadID, @resultLead

Set @rsLead = RetrieveSalesforceObjects('Lead', 'Id', 'Email', '=', '[email protected]')

Set @countLead = rowcount(@rsLead)

output(concat('Number of leads: ', @countLead))

IF @countLead > 0 THEN

    for @i = 1 to @countLead do

        SET @LeadRow = Row(@rsLead, @i)   
        SET @LeadID = Field(@LeadRow ,'Id') 

        output(concat('<br>LeadID: ', @LeadID))

        if not empty(@leadID) then

            SET @resultLead = UpdateSingleSalesforceObject('Lead', @LeadID, 'HasOptedOutOfEmail','True')
            output(concat("<br>resultLead: ", @resultLead))

        else
            output(concat("<br>LeadID not found"))
        endif


    next @i

ENDIF

]%% 
3
  • Thanks for your response!! but this is not working. I dont know the reason but when i remove the line (UpdateSingleSalesforceObject('Lead', LeadID, 'HasOptedOutOfEmail','True')) the cloud page starts previewing. I have used the same code to update the same field in contact.
    – R Suri
    Commented Jun 21, 2018 at 13:50
  • Now you know where to look. What about the HasOptedOutOfEmail property? Does that exist on your Lead object? I'm assuming the @LeadID variable has a value, correct? Commented Jun 21, 2018 at 14:26
  • yes @LeadID has a value, i have printed these values on page. HasOptedOutOfEmail is a field on lead object. This is quite strange that the same code is working for contact object which also has the same field.
    – R Suri
    Commented Jun 22, 2018 at 7:38

You must log in to answer this question.

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