In Marketing Cloud, I have a CloudPages form that syncs data into my connected Health Cloud Org on form submission. I have a certain logic that determines if that user already exists in Health Cloud. If they already exist, then I only update 1 field (@pcplist
). If they don't exist, a new Lead is created. Here is that code for updating that certain field:
/* Contact Check */
set @rsContact = RetrieveSalesforceObjects('Contact', 'Id', 'FIRST_NAME_UPPER__c', '=', @fname, 'LAST_NAME_UPPER__c', '=', @lname, 'EMAIL_UPPER__c', '=', @email)
if RowCount(@rsContact) > 0 then
set @row = row(@rsContact, RowCount(@rsContact))
set @contactId = Field(@row, 'Id')
set @isContact = 'true'
endif
/* Lead Check */
set @rsLead = RetrieveSalesforceObjects('Lead', 'Id', 'FIRST_NAME_UPPER__c', '=', @fname, 'LAST_NAME_UPPER__c', '=', @lname, 'EMAIL_UPPER__c', '=', @email)
if RowCount(@rsLead) > 0 then
set @row = row(@rsLead, RowCount(@rsLead))
set @leadId = Field(@row, 'Id')
set @isLead = 'true'
endif
/* SF functions */
if @isContact == 'true' then
if @pcplist == 'true' then
/* set @row = row(@rsContact, 1) */
/* set @contactId = Field(@row, 'Id') */
set @result = UpdateSingleSalesforceObject('Contact', @contactId, 'Primary_Care_Physician__c', 'true', 'Web_Form_Submission_Date__c', @today)
endif
elseif @isLead == 'true' then
if @pcplist == 'true' then
/* set @row = row(@rsLead, 1) */
/* set @leadId = Field(@row, 'Id') */
set @result = UpdateSingleSalesforceObject('Lead', @leadId, 'Primary_Care_Physician__c', 'true', 'Web_Form_Submission_Date__c', @today, 'LeadSource', 'Web Form')
endif
else
set @id = CreateSalesforceObject('lead', 11, 'FirstName', @leadfirstname, 'LastName', @leadlastname, 'Email', @email,'PostalCode', @zip, 'Primary_Care_Physician__c',@pcplist,
'Web_Form_Submission_Date__c', @today, 'Status', 'New', 'Web_Form_Age__c', @age, 'LeadSource', 'Web Form', 'Phone', @phone, 'Health_Wellness_Tips__c', @opt)
/*set @rsLead2 = RetrieveSalesforceObjects('Lead', 'Id, Email', 'FIRST_NAME_UPPER__c', '=', @fname, 'LAST_NAME_UPPER__c', '=', @lname, 'EMAIL_UPPER__c', '=', @email)
if RowCount(@rsLead2) == 1 then
set @isLead = 'true'
set @row = row(@rsLead2, 1)
set @leadId = Field(@row, 'Id')
set @email = Field(@row, 'Email')
endif*/
set @leadId = @Id
endif
I tried updating the code to also update the @opt field but when I use this code, it updates BOTH the @opt and @pcplist for the existing Contact or Lead but then a duplicate Lead is created.
/* SF functions */
if @isContact == 'true' then
/* set @row = row(@rsContact, 1) */
/* set @contactId = Field(@row, 'Id') */
set @result = UpdateSingleSalesforceObject('Contact', @contactId, 'Primary_Care_Physician__c', @pcplist, 'Web_Form_Submission_Date__c', @today, 'Health_Wellness_Tips__c', @opt)
endif
elseif @isLead == 'true' then
/* set @row = row(@rsLead, 1) */
/* set @leadId = Field(@row, 'Id') */
set @result = UpdateSingleSalesforceObject('Lead', @leadId, 'Primary_Care_Physician__c', @pcplist, 'Web_Form_Submission_Date__c', @today, 'LeadSource', 'Web Form', 'Health_Wellness_Tips__c', @opt)
endif
else
I don't want that duplicated Lead to be created. I want the logic to be:
- If this record is already a Contact --> then update the
@pcplist
(Primary_Care_Physician__c) and@opt
(Health_Wellness_Tips__c) fields based on the values in the form submission - If the record is already a Lead, do the same. I can't figure out what I'm missing.
UpdateSingleSalesforceObject
function is executed, you do not get theHealth_Wellness_Tips__c
field updated with the@opt
value but it works withPrimary_Care_Physician__c
+@pcplist
, is that correct? And then the second issue is that you have a duplicated Lead created. Please, upload your full code with Lead creation logic as well, since now it seems incomplete and hard to understand.