2

I am using this code

 var @rs, @row, @Id, @Fname, @Lname
      SET @rs= RetrieveSalesforceObjects('Lead', 'Id, FirstName,LastName', 'email', '=', @email)
      IF NOT Empty(@rs) THEN
        SET @row = ROW(@rs,1)
        SET @Id = FIELD(@row,"Id")
        SET @Fname = FIELD(@row,"FirstName")
        SET @Lname = FIELD(@row,"LastName")

      ENDIF




    ENDIF

    ]%%
    <div class="container">
      <p>
        %%[ if RequestParameter("email") != "" then ]%%
          <p>
            %%=v(@Id)=%%
            Thank you, your preferences have been saved. (actually need to only show this on success, need error handling)
          </p>

I know if have two ENDIFs there but there is another IF above that I'm not showing here. My Retrieve SalesforceObjects is working fine without the IF NOT EMPTY, but with it, my other variables never get set. Why is this? I don't think it's case sensitive, but I've tried it with a number of different cases and it never works. It only works if I remove the if statement entirely. Are we not allowed to nest IF statements in Ampscript?

1 Answer 1

5

I believe that function returns a row set, so you'd need to check the rowcount() instead of using empty().

%%[

var @rs, @rc, @row, @Id, @Fname, @Lname
set @rs = RetrieveSalesforceObjects('Lead', 'Id, FirstName,LastName', 'email', '=', @email)
set @rc = rowcount(@rs)

IF @rc > 0 THEN
  SET @row = ROW(@rs,1)
  SET @Id = FIELD(@row,"Id")
  SET @Fname = FIELD(@row,"FirstName")
  SET @Lname = FIELD(@row,"LastName")
ENDIF

]%%
1
  • weird ok this other thread referenced it in the way I had it. But yours worked! thank you so much! Commented Aug 14, 2017 at 19:11

You must log in to answer this question.

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