0

I need to generate a url from multiple fields on a object. This is what I have so far

"https://www.companyabc.com/property-details/" + 
SUBSTITUTE(pba__Address_pb__c + " " + pba__City_pb__c + " " + pba__PostalCode_pb__c 
+ " " + pba__StateCode_pb__c + " " + pba__Country_pb__c, 
"(\\D)+(\\d)+[^%$#@&!*()^+_-][^=,<.>/?~`]", "-")

It should generate

https://www.companyabc.com/property-details/1234-Main-St-Los-Angeles-91234-CA-USA

But instead is generating

https://www.companyabc.com/property-details/1234 Main St Los Angeles 91234 CA USA

Is what I'm trying to achieve possible?

0

Without knowing your exact use case, it looks like you're missing the substitute for spaces; add the following to your formula:

SUBSTITUTE( (YourFormula) , " ", "-")

That should replace the spaces with dashes. You might however want to clean up your formula a little bit, escape parenthesis, brackets and other characters where necessary.

  • but what about special characters such has periods? how would I remove all non-alphanumeric characters with dashes? – Tyler Zika Jan 10 '18 at 22:40
  • 1
    Formulas will get very complex and may cross the size limits. An Apex trigger removing the non alpha characters in your fields may be a more solid option here – Fred Jan 10 '18 at 23:07
  • I agree. My boss wants a formula field though D: – Tyler Zika Jan 10 '18 at 23:16

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.