1

I have created two custom objects. Opportunity Expert and Expert with a lookup relationship to Opportunities, however on the Expert element there is a button called "New Opportunities Expert". It looks up Opps and allows you to add a new opportunities expert to the Opp from the Expert object.

Is there a way to first check the opp stage when the button is clicked and if stage not in contacting display a message saying opportunity not in contacting stage and if the stage is in contacting allow users to create the opportunities expert. I have recreated the button but just unsure if I can first look at the opp then redirect to the new opportunities expert page. This is the button:

https://tei.my.salesforce.com/a0D/e?CF00NE00000027Bwu={!Expert__c.Firstname__c}+{!Expert__c.Lastname__c}&CF00NE00000027Bwu_lkid={!Opportunities_Expert__c.ExpertId__c}&saveURL=%2F{!Opportunities_Expert__c.ExpertId__c}&retURL=%2F{!Opportunities_Expert__c.ExpertId__c}

2 Answers 2

0

You can do it with a JavaScript button but it might work like rubbish in Lightning Experience and Salesforce1.

This should get you started: https://salesforce.stackexchange.com/questions/4627/how-to-customize-the-error-message-thrown-by-approval-process

(it's an old answer, you might be able to make-do without querying, just with merge field checking but the idea is the same).


I'd advise you to try something more native instead that will work everywhere:

  • lookup filter?
  • validation rule (yes, that means it'll display the error only when they actually try to save)
  • formula field that displays "sorry, wrong stage" or your link
  • see if you could put some conditional logic in a Chatter Action that would create new record
  • (development needed) make a small lightning component or VF page that will hold your logic
1
  • Thank you, I went with the validation rule.
    – R.Marin
    Oct 6, 2017 at 15:08
0

If you want to add such complicated logic to Button, you need first create custom page on Visualforce with custom Apex controller. This page should look like standard page that you currently have. Next, you need to add button which you need using <apex:commandButton> tag and implement action-method in page controller. This method will execute required validation and do redirect to page for creation new record or show alert message on current page.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.