0
%%[
set @id = _subscriberkey
set @communities = 'Community-id' /* replace this id with your community ID */
var @createdemographic
set @createdemographic = CreateSalesforceObject(
  'Demographics__c', 5,
  'Contact__c', @id,
  'Community__c', @communities,
  'Answer__c', 'Yes',
  'Name', 'Requested a call back?',
  'MCSource__c', 'CALLBACK-6JUNE'
)
]%%

This is my AMPSCRIPT to create a new record for my custom object 'Demographics'. This creates multiple entries when the user visits the cloud page. How can I limit it to just one entry per contact?

1 Answer 1

0

You can implement a check to see if an entry already exists for the contact before creating a new one. This can be achieved by using the Lookup function to search for existing records in the Data Extension or Salesforce object. If an entry exists, you can skip the creation process.

%%[
set @id = _subscriberkey
set @communities = 'Community-id' /* replace this id with your community ID */

/* Check if an entry already exists for the contact */
set @existingRecord = Lookup('Demographics__c', 'Id', 'Contact__c', @id, 'Community__c', @communities)

if empty(@existingRecord) then
  /* No existing record found, create a new one */
  var @createdemographic
  set @createdemographic = CreateSalesforceObject(
    'Demographics__c', 5,
    'Contact__c', @id,
    'Community__c', @communities,
    'Answer__c', 'Yes',
    'Name', 'Requested a call back?',
    'MCSource__c', 'CALLBACK-6JUNE'
  )
else
  /* Record already exists, do not create a new one */
  set @message = "Record already exists for this contact."
endif
]%%

You must log in to answer this question.

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