We are using the following AMPscript to:
- Retrieve the PersonContactId value from a Salesforce Account object (based on an Id value in the Sendable Data Extension)
- Create a new record in the Salesforce CampaignMember object
Here's the code:
%%[ var @contactId, @campaignId, @id, @contactRows, @limitRow set @id = Id set @campaignId = '70190000000sgS9' set @contactRows = RetrieveSalesforceObjects('Account', 'PersonContactId','Id', '=', @id) set @limitRow = Row(@contactRows, 1) set @contactId= Field(@limitRow, 'PersonContactId') CreateSalesforceObject( 'CampaignMember', 3, 'CampaignId',@campaignId, 'ContactId',@contactId, 'Status','Sent' ) ]%%
This works, but the
CreateSalesforceObject() function is executed when the email is previewed in Marketing Cloud (therefore creating a record in Salesforce).
Is there a way to only execute the
CreateSalesforceObject() function when the email is sent and not previewed?