What language is this Salesforce code that I need to wrap?

Viewed 43

I'm working on a Salesforce coding issue. Let me preface this by saying I'm not a developer or Salesforce expert.

  1. What language is this?

     Data Type   FormulaThis formula references multiple objects      
     IF (Fulfillment_Submission_Form_URL__c <> "" && CONTAINS(Fulfillment_Submission_Form_URL__c, "qualtrics"),
    
     Fulfillment_Submission_Form_URL__c &
    
     (IF (CONTAINS(Fulfillment_Submission_Form_URL__c,"?SID="), "&", "?")) &
    
     (IF (CONTAINS(TEXT(Type__c), "Site Visit"),
     "ContactId="&Statement_of_Work__r.Contractor_Contact__c&
     "&CoachType="&SUBSTITUTE(Statement_of_Work__r.Work_Type__r.Name," ","%20")&
     "&CoachName="&SUBSTITUTE(Statement_of_Work__r.Contractor_Name__c," ","%20")&
     "&InitPartId="&Initiative_Participation__r.Id&
     "&InstitutionName="&substitute(substitute(SUBSTITUTE(Institution_Name__c," ","%20"),")",""),"(","")&
     "&AccountId="&Initiative_Participation__r.Participating_Institution__r.Id&
     "&TodaysDate="&TEXT(TODAY())&
     "&SOWLineItemId="&Id&
     "&LeaderCollege="&Initiative_Participation__r.ATD_Leader_College_Status__c&
     "&SVRCompleted="&TEXT(Count_of_Site_Visit_Fulfillments__c)&
     "&SVRRequired="&TEXT(Number_of_Work_Units_Allocated__c),
    
     IF (CONTAINS(TEXT(Type__c), "Feedback"),
     "InitPartId="&Initiative_Participation__r.Id&
     "&SOWLineItemId="&Id&
     "&ReportYear="&Statement_of_Work__r.SOW_Year__c&
     "&UserId="&Contractor_User_Id__c&
     "&InstitutionName="&substitute(substitute(SUBSTITUTE(Institution_Name__c," ","%20"),")",""),"(",""),
     "")
     ))
    
     ,"")
    
  2. Essentially it's pulling a link from another product we've integrated it with. We then take the basic link and reformat it to add parameters.

The problem is when it pulls in some parameters (ex: CoachName) the Coach entered their name in strange formats like: John (Coach) Doe.

So when the script outputs a URL that includes parameters it breaks at the &CoachName=John%20(Coach)% portion of the URL. Any easy way to work around this by modifying the script? Unfortunately we DO need that (Coach) identifier because the system we push to grabs that as well.

1 Answers

It's formula syntax, I'd compare it to Excel-like formulas. There's self-paced training if you don't want to read documentation. And as it's not exactly code-related you may have more luck on dedicated site, https://salesforce.stackexchange.com/. More admins lurk there.

So you do want that "(Coach)" to go through but it breaks the link? Looks like ( is a special character. It's not technically wrong to have unescaped parentheses, if it breaks that other site you might want to contact them and get their act together. RFC doesn't force us to encode them but looks like you'll have to to solve it at least in the short term: https://webmasters.stackexchange.com/questions/78110/is-it-bad-to-use-parentheses-in-a-url

Instead of poor man's encoding (SUBSTITUTE(Statement_of_Work__r.Contractor_Name__c," ","%20") try using proper URLENCODE(Statement_of_Work__r.Contractor_Name__c).

Or there's bit more "pro" function called URLFOR but the documentation doesn't make it very clear how powerful the 3rd parameter is with the braces [key1 = value1, key2 = value2] syntax. Basically just pass the parameters and let SF worry about encoding special characters etc.

Read my answer https://salesforce.stackexchange.com/a/46445/799 and there are some examples on the net like https://support.docusign.com/s/articles/DFS-URL-buttons-for-Lightning-basic-setup-limitations?language=en_US&rsc_301

Related