0

I'm trying to fetch the data from SalesCloud. The codes currently are hosted in CloudPages, and I'm using the SFMC test sent from the email in Content Builder to pass the subscriber details to the cloud pages.

This is the CTA from the email: <a href="%%=CloudPagesURL(1663)=%%" style="color: #426BB3; text-decoration:none;" target="blank">Manage Preferences</a>

And, this is the full code in the cloudPages:

<script runat="server">
  Platform.Load("Core","1.1.1");
  try{
</script>

%%[
SET @contactId = _subscriberkey

IF NOT EMPTY(@contactId) THEN

/* fetch data from Sales Cloud to show in the form */

SET @subscriberRows = RetrieveSalesforceObjects(
   "Contact",
   "Id,FirstName,LastName,Email,HasOptedOutOfEmail",
   "Id", "=", @contactId
   )
   
  IF RowCount(@subscriberRows) > 0 THEN

  SET @row = row(@subscriberRows,1)
  SET @FirstName = field(@row,"FirstName")
  SET @LastName = field(@row,"LastName")
  SET @Email = field(@row,"Email")
  SET @HasOptedOutOfEmail = field(@row,"HasOptedOutOfEmail")
]%%

<h2>Update your profile:</h2>
 <form action="%%=RequestParameter('PAGEURL')=%%" method="post">
  <label>First name: </label><input type="text" name="firstname" value="%%=v(@FirstName)=%%"><br>
  <label>Last name: </label><input type="text" name="lastname" value="%%=v(@LastName)=%%"><br>
  <label>Email: </label><input type="text" name="email" value="%%=v(@Email)=%%"><br>
</form>

%%[ELSE]%%

Errors: No records found!

%%[ENDIF ELSE]%%

Errors: Mmissing subscriber key!

%%[ENDIF]%%


<script runat="server">
}
catch(e) {
 Variable.SetValue("errorMessage", Stringify(e.message) + Stringify(e.description));
}
</script>
 
<script runat="client">
console.log(`%%=v(@errorMessage)=%%`);
</script>

But, it's currently returning this error from the console:

"Call to retrieve records for salesforceobject Contact failed! Error in the application.
API Fault: Salesforce.com Fault thrown.
    Exception Type:UnexpectedErrorFault
    Exception Code:INVALID_QUERY_FILTER_OPERATOR
    Exception Message:
HasOptedOutOfEmail FROM Contact WHERE Id = 'xxx.yyy@example.com.au'
                                      ^
ERROR at Row:1:Column:74
invalid ID field: xxx.yyy@example.com.au""ExactTarget.OMM.FunctionExecutionException: Call to retrieve records for salesforceobject Contact failed! Error in the application.
API Fault: Salesforce.com Fault thrown.
    Exception Type:UnexpectedErrorFault
    Exception Code:INVALID_QUERY_FILTER_OPERATOR
    Exception Message:
HasOptedOutOfEmail FROM Contact WHERE Id = 'xxx.yyy@example.com.au'
                                      ^
ERROR at Row:1:Column:74
invalid ID field: xxx.yyy@example.com.au
  Error Code: RETRIEVESFOJBECTS_FUNC_ERROR
 - from Jint

"

Anyone has idea what could go wrong in here? Perhaps in the Salesforce setup?

Thanks,

3
  • 3
    It seems you are using an email address as a unique identifier of a person (Subscriber Key). Try using a Salesforce Contact Id instead: test with a record that uses a Salesforce Contact Id as a Subscriber Key.
    – zuzannamj
    Aug 2 at 6:37
  • 3
    It is also best practice to remove PII from questions posted here on SFSE. I have edited the email address for you. Aug 2 at 7:06
  • You code works, but as @zuzannamj said, your subscriber key must be bound to a Contact Key actually existing in the Salesforce Contact object. Aug 2 at 10:34

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.