1

I have a Smart Capture form that is used to capture opt-ins for Salesforce Contacts. I want the form to use the contact's first name and phone number to find the person's Contact ID and then put the contact ID into the data extension tied to the Smart Capture form.

I have the below code, but it's not finding a Contact ID even though a Contact ID exists.

%%[

var @subscriberRows

set @subscriberRows = RetrieveSalesforceObjects(
"Contact",
"ID,FirstName",
"phone", "=", @phonenumber,
"FirstName", "=", @FirstName )

if RowCount(@subscriberRows) == 1 then /* there should only be one row */
var @subscriberRow, @firstName, @lastName, @phonenumber
set @subscriberRow = Row(@subscriberRows, 1)
set @firstName = Field(@subscriberRow, "FirstName")
set @lastName = Field(@subscriberRow, "LastName")
set @phonenumber = Field(@subscriberRow, "phonenumber")

/* Update Data Extension with Contact ID */
InsertDE("SMS_Optin_test", "FirstName", @firstName, "LastName", @lastName, "PhoneNumber", @phoneNumber, "ContactID", @contactID)
else
/* Contact not found */
set @contactID = "error"
endif
]%%

2 Answers 2

1

There is still a chance that there is more than one contact with the same First Name and Phone Number, so you would want to check whether the row set @subscriberRows has only 1 row or not.

You can set fixed values for the issue record and put this code on a Cloud Page to debug. It will show the available contact IDs for a predefined First Name and Phone Number value.

%%[

var @subscriberRows

set @phoneNumber = "PHONE NUMBER"
set @FirstName = "FIRST NAME"

set @subscriberRows = RetrieveSalesforceObjects(
"Contact",
"ID,FirstName,LastName,Phone",
"Phone", "=", @phoneNumber,
"FirstName", "=", @FirstName )

set @rowCount = RowCount(@subscriberRows)
if @rowCount > 0 then
    for @i = 1 to @rowCount do
        set @row = Row(@subscriberRows, @i)
        set @contactID = Field(@row, "ID")
]%%

%%=v(@contactID)=%%<br>

%%[
    next @i
endif    

]%%
-6

The Contact ID is not being retrieved or declared correctly. The script needs to include a line to set @contactID based on the retrieved row. You can try the below code.

%%[ var @subscriberRows, @contactID set @subscriberRows = RetrieveSalesforceObjects( "Contact", "Id,FirstName,LastName,Phone", "Phone", "=", @phonenumber, "FirstName", "=", @FirstName ) if RowCount(@subscriberRows) == 1 then set @subscriberRow = Row(@subscriberRows, 1) set @contactID = Field(@subscriberRow, "Id") set @firstName = Field(@subscriberRow, "FirstName") set @lastName = Field(@subscriberRow, "LastName") set @phonenumber = Field(@subscriberRow, "Phone") InsertDE("SMS_Optin_test", "FirstName", @firstName, "LastName", @lastName, "PhoneNumber", @phoneNumber, "ContactID", @contactID) else set @contactID = "error" endif ]%%

4
  • Clicking on this link I am asked to log in. An outline of your answer would have been useful even if there were a useful text that you recommend. This way the answer is just wasting the time of people looking for an answer. Commented Dec 22, 2023 at 7:48
  • Can you please fix this link and then add some relevant content here? Link only answers are usually removed as they break over time, this one appears broken from the outset!
    – Matt Lacey
    Commented Dec 22, 2023 at 12:50
  • Also, looking at your blog, where you have created 12 articles over 2 days shows some indications of being built using generative AI. Please read this help article on why content created using Gen AI is not allowed on StackExchange sites Commented Dec 22, 2023 at 14:02
  • My old blogs got deleted. The content I uploaded was the backup content left with me. If you don't find it helpful, don't follow! Commented Dec 22, 2023 at 23:40

You must log in to answer this question.

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