function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Marry SteinMarry Stein 

Conditionally URL Button


Hey Guys,

i am looking for a "best practice" solution, to create a conditionally url button. The button should be placed on the standard page layout.
Related to a value of the object, the button button should redirect the user to a page.

For example, if the status is x, redirect to a new task.
if the status is y, redirect to the homepage.
if the status is z, redirect to an external page.

Unfortunately, a javascript button is not a soultion for lightning.

I have created a controller and a methode to create a conditionally PageReference for each case. I dont think that this solution is best practice. Moreover, i used simply urls like
1new PageReference('https://...............+lead.id');
what is definitely not best practise.  So my button opens the page which is fireing the action methode automatically.

Conclusion, i am looking for : 
- a solution for lightning and classic
- a button placed on the standard page layout
- the button should redirect to different pages related to a value of the object
- a more best practice solution than mine 

I appreciate your help ! 

Cheers, 
Marry
Best Answer chosen by Marry Stein
Pradeep JonnalagaddaPradeep Jonnalagadda
Hi Marry,

It's very much possible to use an if statement in a custom formula. Please look at this code snippet. The below code snippet opens a google US search if the country is USA else google UK search. 

{! IF(Sample.BillingCountry = "US", "http://maps.google.com/maps?q="&Sample.BillingStreet& "+"&Sample.BillingCity&"+"&Sample.BillingState&"+"&Sample.BillingCountry, (IF(Sample.BillingCountry = "UK", "http://maps.google.co.uk/maps?q="&Sample.BillingStreet &"+"&Sample.BillingCity&"+"&Sample.BillingCountry, "http://maps.google.com"))) }

This is from the help article: https://help.salesforce.com/articleView?err=1&id=customize_functions_i_z.htm&type=5

Please let me know why you think you cannot use an if statement.

Pradeep

All Answers

Pradeep JonnalagaddaPradeep Jonnalagadda
Marry-
You should be able to do this using Custom buttons. 
Create the custom button for the object by navigating to  Account- Object->  'Button, Link & Actions'.  When you create the button use the formula to compare the object values.
Defining custom button:
https://help.salesforce.com/articleView?id=defining_custom_links_fields.htm&type=5

Custom button with a formula 
https://help.salesforce.com/articleView?err=1&id=customize_functions_i_z.htm&type=5

Finally, use the custom button in your account page layout.
Let me know if that helped?

Pradeep
Marry SteinMarry Stein
Hi Pradeep,

thanks for your reply. Unfortunately, it is not possible to use a if statement in a custom button formula. 

I appreciate your help,

Marry
Pradeep JonnalagaddaPradeep Jonnalagadda
Hi Marry,

It's very much possible to use an if statement in a custom formula. Please look at this code snippet. The below code snippet opens a google US search if the country is USA else google UK search. 

{! IF(Sample.BillingCountry = "US", "http://maps.google.com/maps?q="&Sample.BillingStreet& "+"&Sample.BillingCity&"+"&Sample.BillingState&"+"&Sample.BillingCountry, (IF(Sample.BillingCountry = "UK", "http://maps.google.co.uk/maps?q="&Sample.BillingStreet &"+"&Sample.BillingCity&"+"&Sample.BillingCountry, "http://maps.google.com"))) }

This is from the help article: https://help.salesforce.com/articleView?err=1&id=customize_functions_i_z.htm&type=5

Please let me know why you think you cannot use an if statement.

Pradeep
This was selected as the best answer
Marry SteinMarry Stein
Hey Pradeep,
my bad, its not possible to use actions like 'LogaCall' in an if statment. Thanks for your effort. I will mark your answer as best answer, because my question was formulated incorrectly.  Shame on me ;)

Greetings Marry
Neil Wingate 7Neil Wingate 7
This worked perfectly.... (passing Name OR Site value depending...... to a flow's variable.... so do not have to complicate the flow quite as much.


User-added image