3

I'm trying to retrieve some fields from the Account object in a Salesforce org connected by the MC Connector in order to eventually pre-populate a preference page. This is the AMPscript I'm using but It's not working and I can't see any issues with it.

%%[
    SET @SubscriberKey = '0030N000025L06hQAC'
    SET @rs = RetrieveSalesforceObjects("account", "Email_Opt_In__c,Phone_Opt_In__c", "Contact_ID__c", "=", @SubscriberKey)

    IF NOT Empty(@rs) THEN 
      Set @row = ROW(@rs,1)
      Set @Email = FIELD(@row,"Email_Opt_In__c")
      Set @Phone = FIELD(@row,"Phone_Opt_In__c")
    ENDIF

    IF @Email == 'TRUE' THEN
     SET @EmailValue = 'Checked'
    ENDIF
    IF @Phone == 'TRUE' THEN
     SET @PhoneValue = 'Checked'
    ENDIF
    ]%%

Subkey: %%=v(@SubscriberKey)=%%
<br>
Email: %%=v(@Email)=%%
<br>
Phone: %%=v(@Phone)=%%
<br>
EmailValue: %%=v(@EmailValue)=%%
<br>
PhoneValue: %%=v(@PhoneValue)=%%
<br>

I've hardcoded the subscriberkey for now and I've checked the Account synchronised data extension and the person exists in there with the correct ID, so I'm a bit stumped. So far all I'm seeing is SubscriberKey. Any help would be much appreciated.

2
  • Are you using Person Accounts in Salesforce CRM? I'm asking because you are checking the account object for contact information. Also, do you get any errors or is just not pulling data? Mar 19, 2019 at 20:35
  • Yes, we're using person accounts and the Contact_id is our subscriberkey. All the fields I need to retrieve and update sit on the Account object. I don't get any errors, I just cant pull any data.
    – Kai Curtis
    Mar 19, 2019 at 21:38

4 Answers 4

0

In the case of using PersonAccounts you need to query against PersoncontactId. This is a standard field that comes with the activation of PersonAccounts. You don't actually need to create a custom field for this. You can also see this field when you configure your synchronized data source.

Also, as a side note: Custom fields on contact level will appear in PersonAccounts with __pc at the end. So you can use this syntax to query against contact fields in accounts should you need to extend your current query in the future.

3
  • So do you think I need to change; RetrieveSalesforceObjects("account", "Email_Opt_In__c,Phone_Opt_In__c", "Contact_ID__c", "=", @SubscriberKey) To: RetrieveSalesforceObjects("account", "Email_Opt_In__c,Phone_Opt_In__c", "PersoncontactId", "=", @SubscriberKey)
    – Kai Curtis
    Mar 21, 2019 at 11:49
  • It's definitely worth a try ;) Mar 21, 2019 at 23:25
  • Tried and still no luck. Any other ideas?
    – Kai Curtis
    Mar 22, 2019 at 10:09
0

Instead of:

IF NOT Empty(@rs) THEN 

Try this instead:

IF RowCount(@rs) > 0 THEN 

Also, output the RowCount(@rs) to see if you actually have a row returned as a way to debug.

0

Person Accounts combine both Contact and Account where some Contact Info is also displayed in the Account Detail page. But in this case, it could be that those are Contact data attributes that need to be retrieved from the Contact object.

    SET @rs = RetrieveSalesforceObjects("Contact", "Email_Opt_In__c,Phone_Opt_In__c", "Id", "=", @SubscriberKey)
0

After a lot of back and forward with Salesforce Support and some trial and error. This is the code that worked.

%%[
SET @SubscriberKey = '0030N000025L06hQAC'
set @subscriberRows = RetrieveSalesforceObjects("Account","Id, Email_Opt_In__c, Phone_Opt_In__c","Contact_ID__c", "=",@SubscriberKey)

if RowCount(@subscriberRows) == 1 then 
  set @subscriberRow = Row(@subscriberRows, 1)
  set @EmailValue = Field(@subscriberRow, "Email_Opt_In__c")
  set @PhoneValue = Field(@subscriberRow, "Phone_Opt_In__c")
endif

]%%

You must log in to answer this question.

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