1
SET @emailaddress = QueryParameter("email") /* gets the encrypted string */)
SET @thanks = QueryParameter("thanks")

set @Contact = RetrieveSalesforceObjects("Contact","Id,FirstName,MobilePhone,LastName,Preferred_Business_Email_Address__c,Fund_Overview_Webcasts__c,BDC_FA__c,Global_REIT_II_Communication__c,Fund_Updates_or_News__c,Marketing_Materials__c,Individual_Communications__c,SMS_Message_Opt_In__c,Preferred_First_Name__c,Preferred_Last_Name__c,ISC_Name__c,ISC_Email__c,ISC_Phone__c,ISC_Title__c,Contact_Owner_Name__c,Contact_Owner_Email__c,Contact_Owner_Phone__c,Contact_Owner_Title__c,Preferred_Broker_Dealer_Name__c,Broker_Dealer_Name__c,Email,HasOptedOutOfEmail","Email", "=", v(@emailaddress)) 
Set @ContactRow = ROW(@Contact,1)

I am building a landing page in MC that will display a persons information based on the information they have in SF, they will be able to submit a form and update their preference (its a preference center).

I am using the url to populate their email address and use that to query back to SF for the right contact. (example: testsite.com/Main?email=testemail@gmail.com)

My problem is if a user somehow gets to this page through other means or they don't have a record in SF but they do in MC they will either get a really ugly error message or the LP will go and find the first contact in SF and display that..

So I need a way for my code to tell me they aren't in there then redirect them.

set @rowCount = rowcount(@ContactRow)

IF @rowCount > 0 THEN

I've seen something like this done before but i've only got it to work with a row pull from a Data Extension.

Has anyone solved this before?

2 Answers 2

5

You have to use Redirect AmpScript function to redirect subscribers if record doesn't exist in Salesforce and below is sample code.

%%[
SET @emailaddress = QueryParameter("email") /* gets the encrypted string */)
SET @thanks = QueryParameter("thanks")

SET @Contact = RetrieveSalesforceObjects("Contact","Id,FirstName,MobilePhone,LastName,Preferred_Business_Email_Address__c,Fund_Overview_Webcasts__c,BDC_FA__c,Global_REIT_II_Communication__c,Fund_Updates_or_News__c,Marketing_Materials__c,Individual_Communications__c,SMS_Message_Opt_In__c,Preferred_First_Name__c,Preferred_Last_Name__c,ISC_Name__c,ISC_Email__c,ISC_Phone__c,ISC_Title__c,Contact_Owner_Name__c,Contact_Owner_Email__c,Contact_Owner_Phone__c,Contact_Owner_Title__c,Preferred_Broker_Dealer_Name__c,Broker_Dealer_Name__c,Email,HasOptedOutOfEmail","Email", "=", v(@emailaddress)) 

IF RowCount(@Contact) > 0 Then
    SET @FirstName = Field(Row(@Contact,1),"FirstName")
    SET @LastName = Field(Row(@Contact,1),"LastName")
Else
    Redirect("Error Page URL")
EndIf
]%%
0
1

Before calling the RetrieveSalesforceObjects() function, I would recommend checking the value of @emailaddress. I suspect your code is returning the 1st contact record when this variable is blank. Consider using the Empty() function. You could also verify the format of the @emailaddress variable using the isEmailAddress() function.

%%[
SET @emailaddress = QueryParameter("email") /* gets the encrypted string */)
SET @thanks = QueryParameter("thanks")

if Empty(@emailaddress) then
    Redirect("Error Page URL")
else
    SET @Contact = RetrieveSalesforceObjects("Contact","Id,FirstName,MobilePhone,LastName,Preferred_Business_Email_Address__c,Fund_Overview_Webcasts__c,BDC_FA__c,Global_REIT_II_Communication__c,Fund_Updates_or_News__c,Marketing_Materials__c,Individual_Communications__c,SMS_Message_Opt_In__c,Preferred_First_Name__c,Preferred_Last_Name__c,ISC_Name__c,ISC_Email__c,ISC_Phone__c,ISC_Title__c,Contact_Owner_Name__c,Contact_Owner_Email__c,Contact_Owner_Phone__c,Contact_Owner_Title__c,Preferred_Broker_Dealer_Name__c,Broker_Dealer_Name__c,Email,HasOptedOutOfEmail","Email", "=", v(@emailaddress)) 

    IF RowCount(@Contact) > 0 Then
        SET @FirstName = Field(Row(@Contact,1),"FirstName")
        SET @LastName = Field(Row(@Contact,1),"LastName")
    Else
        Redirect("Error Page URL")
    EndIf
EndIf
]%%

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.