1

I have one custom button with Javascript code in Salesforce classic. In Lightning experience, i can not see this button as lightning doesnt support buttons with js code. What i need to do to convert this button to work in lightning? Code on button is-

{!REQUIRESCRIPT("/soap/ajax/9.0/connection.js")}

var count = '{!Contract.Count__c}';
if(count > 300)
window.parent.location.href = "/apex/page1?id={!Contract.Id}";

else
window.parent.location.href = "/apex/page2?id={!Contract.Id}";
2
  • 2
    Change the button to goto a URL and use a formula field to set the URL
    – Eric
    Feb 7, 2017 at 5:15
  • 2
    To expand on @Eric 's comment, if all you wanted to do was perform a redirection, you could change the button's Content Source to URL and change the formula to: /apex/page{!IF(Contract.Count__c > 300,'2','1')}?id={!Contract.Id}
    – martin
    Feb 7, 2017 at 5:30

1 Answer 1

0

The cleanest approach would be to simply build a Visualforce page for this and a controller linked to the visualforce page .

You will create a standard controller extension for same

Sample code

<apex:page standardController="Contract" extensions="myControllerExtension" action="{!Redirect}">

Apex code

public class myControllerExtension {

  private final Contract Contract;

   public myControllerExtension(ApexPages.StandardController stdController) {
      this.Contract = (Contract)stdController.getRecord();
   }

   public PageReference redirect() {
    //Query with necessary Id for your field
      Contract = [Select Id,Count from Contract limit 1];
      if(Contract.count>300){
        return pagereference ('/page1?'+ContractId);
      }else{
          return pagereference ('/page2?'+ContractId);
      }
   }
}
1
  • Thnaks Mohith for the solution. I will try this also.
    – Sofiya
    Feb 7, 2017 at 5:36

You must log in to answer this question.

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