0

I have a sign up form that upon submission will create a PersonAccount (Account) record in Salesforce. I then want to create the corresponding Contact in SFMC so that we have the values until it syncs over with the connector.

Straight after I have created the Account record with CreateSalesforceObject() I then use RetrieveSalesforceObjects() with the AccountId to try and get the PersonContactId:

  /*Retrieve PersonContactId*/
    set @accountRows = RetrieveSalesforceObjects(
   "Account",
   "PersonContactId",
   "Id", "=", @createAccount)

    if RowCount(@accountRows) == 1 then /* there should only be one row */
        var @subscriberRow, @PersonContactId
        set @subscriberRow = Row(@subscriberRows, 1)
        set @PersonContactId = Field(@subscriberRow, "PersonContactId")
    endif 

However I get the below error message indicating that the PersonContactId value is null.

Invalid row (parameter 1) passed to Field function. Row is null or empty.\r\n Function: Field(@accountRow, "PersonContactId\

This was leading me to assume that the code is querying too quick, before SF has had chance to create all the attributes.

However, I have moved the RetrieveSalesforceObjects to a second cloud page that I redirect to, and also used the SSJS function sleep(milliseconds) to create a 3 second delay. But I am still encountering the issue.

1
  • sidenote, that sleep function is necessary, but 500-1000ms of "sleep" should be enough from my experience. 3seconds sounds like it's too long. Oct 23, 2023 at 6:38

1 Answer 1

1

You made a mistake on this line set @subscriberRow = Row(@subscriberRows, 1). it should be @accountRows instead of @subscriberRows.

I would suggest to fix it like this:

  /*Retrieve PersonContactId*/
    set @accountRows = RetrieveSalesforceObjects(
   "Account",
   "PersonContactId",
   "Id", "=", @createAccount)

    if RowCount(@accountRows) == 1 then /* there should only be one row */
        var @subscriberRow, @PersonContactId
        set @subscriberRow = Row(@accountRows, 1)
        set @PersonContactId = Field(@subscriberRow, "PersonContactId")
    endif 

You must log in to answer this question.

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