-1

I have a requirement in which I have to make a button, that first checks values of some fields and then, if conditions are true, redirects to a visualforce. Something like this:

if(field != value){
   alert('error message')
}else{
  //redirect to visualforce
}

This is for salesforce classic, so, normally, I would use onclick javascript for this. But, they asked to make it so it works for Lightning, BUT in the future, I mean, they wont migrate to Lightning right away. Is there a simple alternative to onclick javascript for classic that achieves this, and would work on lighting? I found a way in which I would create a "OnClickJSUtilityController" and implement an interface to perform the logic (source), but it seems a little too much for something so simple as to check a few fields.

Is there an alternative to this for classic? Thanks!

2 Answers 2

0

You can do this in a VF page associated to the button:

<apex:page standardController="Account"
      action="{!IF(Account.Name<>'foo',
                   NULL,
                   URLFOR($Page.MyPage,Account.Id)
                  )}">
   <apex:pageMessage title="Mymessage" severity="error"/>
</apex:page>

The NULL in the IF means don't redirect anywhere, just render the page.

References

1
  • okay, nice solution, but how do I insert the message in case the condition is true? I know I don't want to redirect to the other page, but how do I show the custom error ? May 9 at 18:36
0

You can replace button URL:

/apex/ApexStart?a=accorto.ProjectLineNS&m=updateProject
&n=projectId&v={!accorto__Project__c.Id}
&r=/{!accorto__Project__c.Id}&q={!URLENCODE('Recalculate Project Actuals')}

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.