I'm currently building a custom preference center and want to give business users an easy option to add/map additional fields for preferences based on salesforce fields.

I'm thinking about creating a mapping Data Extension, that holds all the fieldnames. AMPscript loops through them to display and update the fields within Salesforce.

Is there an option to dynamically retrieve fields from Salesforce?

Instead of setting the Salesforce fields names as hardcoded parameter I'd like to set them via a variable. Something like this:

SET @fields = "field1__c, field2__, field3__c"
SET @SFID = RetrieveSalesforceObjects('Lead', @fields, 'criterea', '=', 'xyz')
  • @glls nope, the link you shared is related to the force.com platform, instead of Marketing Cloud
    – Michael H
    Jan 28 '18 at 18:21
  • ahhh, my bad =)
    – glls
    Jan 28 '18 at 18:22
  • @MichaelH What would be the purpose of this? I suspect this may be an x-y problem. Please consider revising your question to include the purpose behind doing this; perhaps someone will have a way to do what you're trying to do without needing to resort to this technique.
    – sfdcfox
    Jan 28 '18 at 18:24
  • @sfdcfox just added additional information
    – Michael H
    Jan 28 '18 at 18:33

Should be able to set using a variable. This worked for me:

SET @email = "myemail@email.com"
set @bar = "Email"
SET @foo = Concat("id,",@bar)
SET @rowset = RetrieveSalesforceObjects('Contact', @foo, 'Email', '=', @email)


SET @rc = RowCount(@rowset)
IF @rc > 0 THEN
  FOR @j = 1 to @rc DO
    SET @row = Row(@rowset,@j)
    SET @id = Field(@row,'id')
    Output(Concat("<br><br>id: ", @id ))
  Next @j

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.