3

I'm trying to use a Salesforce Object field as an AMPscript variable in an email, when the Salesforce Entry Event is used in a Journey Builder Interaction.

I've created a 'Salesforce Data' event (from the Define Entry Event modal when creating an entry event) using the CampaignMember Object as my Primary Event Object. I want to use the value of the Id field from the CampaignMember Salesforce Object (which I've included as a field in the Event Data when configuring the Event).

The following AMPscript block does not work (note, I am trying to set @campaignMemberId to equal the Id field from the CampaignMember Salesforce Object)

%%[
var @campaignMemberId, @Case, @CaseRow, @barcode

Set @campaignMemberId = Id
set @Case = RetrieveSalesforceObjects("CampaignMember","Coupon_Number__c","Id", "=", @campaignMemberId)
Set @CaseRow = Row(@Case, 1)
Set @barcode = FIELD(@CaseRow, "Coupon_Number__c")

]%%

What syntax should you use to define Salesforce fields in this context so they can be passed from the Event Source to the Email Activity?

5

If you select a 'Salesforce Data' event or 'Salesforce Campaign Event' from the Define Entry Event modal when creating a Journey Builder Event, then the required Attribute Set(s) will be dynamically created in a new Attribute Group named 'Sales and Service Cloud'.

Open Contact Builder and check the Attribute name in the Attribute Set for the variable name to use in AMPScript. For example, in the screenshot below, the Id of the Campaign Member object is CampaignMember:Id.

Sales and Service Cloud Attribute Group

So, simply use CampaignMember:Id in your AMPscript:

%%[
var @campaignMemberId, @Case, @CaseRow, @barcode

Set @campaignMemberId = CampaignMember:Id
set @Case = RetrieveSalesforceObjects("CampaignMember","Coupon_Number__c","Id", "=", @campaignMemberId)
Set @CaseRow = Row(@Case, 1)
Set @barcode = FIELD(@CaseRow, "Coupon_Number__c")

]%%

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.