0

can someone help me to write a code that will retrieve a salesforce object. The name of the field in SF is: Preferred Contact Time The name of the field in MC synced is: Preferred_Contact_Time_Pez__c

This field exists in the lead in SF. Once i get the code, i will put in HTML in an email. Thanks

Im new to AMPSCRIPT and programming in general. Here is the last one i tried,

%%[
    VAR@PreferredContactTime
    SET@PreferredContactTime=RetrieveSalesforceObjects(“Lead”,”FirstName,LastName,Email”,”Id”,”=”,_Subscriberkey) 
    If RowCount(@PreferredContactTime)==1 
        then 
            VAR@PreferredContactTime,@FirstName 
            SET@PreferredContactTime=Row(@PreferredContactTime,1) 
    Endif 
]%%
6
  • What have you tried so far? Where are you stuck?
    – Derek F
    Aug 28, 2019 at 17:48
  • Im new to AMPSCRIPT and programming in general. Here is the last one i tried, <!--%%[ VAR@PreferredContactTime SET@PreferredContactTime=RetrieveSalesforceObjects(“Lead”,”FirstName,LastName,Email”,”Id”,”=”,_Subscriberkey) If RowCount(@PreferredContactTime)==1 then VAR@PreferredContactTime,@FirstName SET@PreferredContactTime=Row(@PreferredContactTime,1) Endif ]%%
    – Ben M.
    Aug 28, 2019 at 18:01
  • Comment length and formatting options are limited. You should add that to your question by making an edit.
    – Derek F
    Aug 28, 2019 at 18:08
  • I added it to the first comment but its not showing so i don't know. You cannot see it in my last comment ?
    – Ben M.
    Aug 28, 2019 at 18:27
  • That's because you started an html comment <!--. When providing code and/or markup (like html) it helps if you tell SFSE to format that text as a block of code. The {} button in the rich text editor formats a highlighted section of text as a code block (ctrl + k, cmd + k on mac, does the same thing)
    – Derek F
    Aug 28, 2019 at 18:46

1 Answer 1

1

Try below code

Assuming Preferred Contact time API as "Preferred_Contact_time__c"

 %%[

var @PreferredContactTime

set @PreferredContactTime = RetrieveSalesforceObjects(
   "Lead",
   "Id, FirstName,LastName,Email, Preferred_Contact_time__c",
   "Id", "=", @Id)

if RowCount(@PreferredContactTime) == 1 then
  var @subscriberRow, @firstName, @lastName, @email, @Preferredname
  set @subscriberRow = Row(@PreferredContactTime, 1)
  set @firstName = Field(@subscriberRow, "FirstName")
  set @lastName = Field(@subscriberRow, "LastName")
  set @email = Field(@subscriberRow, "Email")
  set @Preferredname = Field(@subscriberRow, "Preferred_Contact_time__c")
endif

]%%
7
  • i just tried it, it didn't work
    – Ben M.
    Aug 28, 2019 at 19:32
  • Can you let me know Whether you are using email or ID as subscriberkey Aug 28, 2019 at 19:33
  • Normally i use Lead ID in the entry source of the journey. Because i need to put this code in an email in a journey
    – Ben M.
    Aug 28, 2019 at 19:37
  • I edited the code try once, if not working i will check on that Aug 28, 2019 at 19:46
  • it didn't work. I populate that field in the email like this: %%=v(@PreferredContactTime)=%% , but it's blank which means the code didn't work , My Preferred Contact time API is "Preferred_Contact_Time_Pez__c" and it did put it in the codeyou sent me this way
    – Ben M.
    Aug 28, 2019 at 21:15

You must log in to answer this question.

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