4

I have a custom button on Opportunity and would like to open different visualforce pages with that button, based on logic.

The logic is a little complex, it involves Opportunity record's RecordType Name and Opportunity record's children's fields. So the logic can't be formulated in the formula field given in the new button creation page.

What is the next best alternative to achieve this?

1
  • 1
    why not have ur button execute a java script and embeed different VF page urls based on ur logic
    – Rao
    Commented Jun 25, 2015 at 17:10

2 Answers 2

3

You should use Visualforce behind your button rather than javascript.

In the action attribute of the page you can do all sorts of complex logic rather than using formula field.

lets see some sample example of how you should proceed with the code

<apex:page standardcontroller="Object__c" extensions="MycustomCtrl" action="navigate">

and then use the logic as below in your extension controller

  public class MycustomCtrl{

       private final object__c obj;

       public MycustomCtrl(ApexPages.StandardController stdController) {
          this.obj= (Account)stdController.getRecord();
       }

       public pagereference navigate(){
          pagereference p=new pagereference();//Use pagereference variables
         //Query for the recordtype and name and other fields
         //Use if logic and construct your navigation logic with pagereference variables
       }
 }
0

You should use Javascript behind your button rather than Visualforce. You can do the same logic in JS as you can in Apex without dealing with test rules and other apex restrictions.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .