0

I need to create a custom footer that will dynamically be populated, If the subscriber key is a Salesforce ID (starts with 003(contact), 005(user) or 00q(lead), 001(account) AND it will always be 18 digits, does not contain @ symbol, then we need to display the custom preference center URL 1. If the subscriber key is not a Salesforce ID, i.e. it has an email address then the Custom Preference Center URL 2 must be displayed.

Solution Which I'm thinking:-

  1. Created 2 HTML content that will have a code of Footer, where I'll mention the URL of Profile Centers.

  2. Use those HTML content in Dynamic Content Block-based and apply rules on D.E chosen to show which HTML content needs to be displayed. If the Subscriber key contains 003 or 005 it should display HTML content that has preference Center URL 1. If the Subscriber Key contains @ or .com it should display HTML Content that has a preference center 2 URL.

I have a question can a subscriber Key column hold Salesforce ID and Email Address as a value ?? which we will use to create a rule in the dynamic content block?

Someone else has some other alternative solution to this requirement??

Modified Code:

%%[
SET @SFIDregEx = "^00[135Q][a-zA-Z0-9]"
SET @EmailRegEx = "^([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,})$"
SET @subKey = AttributeValue("_subscriberkey")
SET @Email = AttributeValue("emailaddr")
SET @match1 = RegExMatch(@subKey, @SFIDregEx1, 0)
SET @match2 = RegExMatch(@Email, @EmailRegEx, 0)
SET @len1 = length(@match1)
SET @len2 = length(@match2)
IF @len1 > 0 THEN
SET @redirect = "https://google.com" -----// example
ENDIF
IF @len2 >0 THEN
SET @redirect = "https://trailhead.com" -----//example
ELSE
SET @redirect = "https://yahoo.com" ------//example
ENDIF
]%%
2
  • Hi Abishek. The purpose of this community is not to provide turnkey solutions based on requirements. I will advise you to look into Ampscript and especially RegExMatch function. Try this regex: ^00[135Q][a-zA-Z0-9]{12,15} - Please provide code example of what you have tried so far. Sep 7 '20 at 9:22
  • Hey Lukas, thanks for the comment, I've created the solution based on creating a dynamic content block. I just want to know, for now, can we have values as Email Id and Salesforce Id in the Subscriber Key column? which I'm using to create a rule in the Dynamic content block
    – darkCloud
    Sep 7 '20 at 9:39
0

I will recommend using RegEx to identify whether or not your subscriber key is from one of the four valid Salesforce objects, and if not - default to a fallback solution:

%%[
SET @regEx = "^00[135Q][a-zA-Z0-9]{12,15}"
SET @subKey = AttributeValue("_subscriberkey")
SET @match = RegExMatch(@subKey, @regEx, 0, "IgnoreCase")
SET @len = length(@match)
IF @len > 0 THEN
SET @redirect = "https://example.com/unsubSalesforce"
ELSE
SET @redirect = "https://example.com/unsubOther"
ENDIF
]%%
<a href="%%=RedirectTo(@redirect)=%%">Unsubscribe</a>

You might want to pass some parameters to the landing pages, in that case these should be added to @redirect using CONCAT function.

Alternatively, if you want to fetch the entire separate content block for each option, instead of just replacing the URL, you can fetch the entire contentblock using ContentBlockByKey:

%%[
SET @regEx = "^00[135Q][a-zA-Z0-9]{12,15}"
SET @subKey = AttributeValue("_subscriberkey")
SET @match = RegExMatch(@subKey, @regEx, 0, "IgnoreCase")
SET @len = length(@match)
IF @len > 0 THEN
ContentBlockbyKey("unsubSalesforce")
ELSE
ContentBlockbyKey("unsubOther")
ENDIF
]%%

ContentBlockbyKey function references the customer key of a content block, which you can see under preferences:

enter image description here

You can paste the code above into the custom footer field, under Setup > Company Preferences, like this:

enter image description here

However, I would advise against it, as it will both be added to the transactional as well as commercial sends. Adding the footer to the template used for commercial emails is IMHO a better option.


You always need to reference the subscriber key - in both RegExMatch functions, as applying the email matching regex on the email field will always evaluate TRUE:

SET @match2 = RegExMatch(@subKey, @EmailRegEx, 0). 

Also, use ELSEIF in your tests:

IF @len1 > 0 
THEN 
SET @redirect = "https://google.com" -----// example 
ELSEIF @len2 >0 
THEN 
SET @redirect = "https://trailhead.com" -----//example 
ELSE 
SET @redirect = "https://yahoo.com" ------//example 
ENDIF
9
  • Hey @Lukas Lunaow, thanks for the above the solution, it looks like I'm able to achieve what I'm looking for. But I'm not really sure where do I need to apply this formula? actually I'm new to Salesforce Marketing and still learning concepts here. could you please guide me how to use this? Like do I need to create an HTML content block or needs to be applied directly in Footer under Admin > Account Setting. Thanks, Abhishek
    – darkCloud
    Sep 8 '20 at 6:27
  • @abhishekverma - I have updated my answer accordingly. Remember to accept/upvote if it has been helpful Sep 8 '20 at 9:48
  • Hey @lukas It worked well and I've created a Code snippet and used that in my email template. I've also modified your code a bit but it's giving me an error, could you please help me out with that. Also, I'm trying to share the code here but getting error :( pasting code in my main question box on top, please have a look and suggest me what I'm doing wrong
    – darkCloud
    Sep 8 '20 at 10:56
  • Can you post the error medssage here, @abhishekverma Sep 8 '20 at 10:57
  • Hi @Lukas, The subscriber preview failed to generate. Review the details, correct all issues, and try again.An IF statement is not closed with the required ENDIF statement.
    – darkCloud
    Sep 8 '20 at 11:00

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.