0

I have a one click javascript custom button on my opportunity page and I want to add that button on salesforce1. Please help to add this button urgently.

ONE CLICK JAVASCRIPT code of that button is as follows:-

{!REQUIRESCRIPT("/soap/ajax/23.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/23.0/apex.js")} 
var cOpp = new sforce.SObject("Opportunity"); 
var QuoteRecord = sforce.connection.query("Select Opportunity__c,Id From Opportunity_Product__c where Opportunity__c='{!Opportunity.Id}'"); 
var records = QuoteRecord.getArray("records"); 
cOpp.Sales_Area__c = "{!Opportunity.Sales_Area__c}"; 
cOpp.NPD_Required__c = "{!Opportunity.NPD_Required__c}"; 

if(records[0] != null)
{ 
if(!((cOpp.Sales_Area__c == null) || (cOpp.Sales_Area__c == ''))){ 
if((cOpp.NPD_Required__c == true) || (cOpp.NPD_Required__c == 'true')) 
window.open('apex/sendInquirytoSAP?id={!Opportunity.Id}&rNPD=1&scontrolCaching=1','_self'); 
else 
window.open('apex/sendInquirytoSAP?id={!Opportunity.Id}&rNPD=0&scontrolCaching=1','_self'); 
} 
else 
alert('Before trigger to SAP, Please select a SalesArea first.'); 
}
else
{ 
alert('You cannot send Opportunity to SAP as no Opportunity Product is associated with it'); 
}

1 Answer 1

0

Salesforce1 and Lightning experience doesn't not support Javascript buttons. What I did was to create a new visualforce page with the content of the javascript button and call that visualforce page from a button, global action or whatever suits you.

I've been waiting for Salesforce to support this feature in order to move to lightning, most of the logic of our business resides in those buttons that are not supported in Salesforce1 and lightning experience but are supported in Salesforce Classic :(....

7
  • I have wriiten the visualforce as follows:- <apex:page standardController="Opportunity"> <script src="/soap/ajax/29.0/connection.js" type="text/javascript"> </script> <script type="text/javascript"> function open() { try {var cOpp = new sforce.SObject("Opportunity"); var QuoteRecord = sforce.connection.query("Select Opportunity__c,Id From Opportunity_Product__c where Opportunity__c='{!Opportunity.Id}'"); var records = QuoteRecord.getArray("records"); Commented Jun 15, 2016 at 9:20
  • cOpp.Sales_Area__c = "{!Opportunity.Sales_Area__c}"; cOpp.NPD_Required__c = "{!Opportunity.NPD_Required__c}"; if(records[0] != null) { if(!((cOpp.Sales_Area__c == null) || (cOpp.Sales_Area__c == ''))){ if((cOpp.NPD_Required__c == true) || (cOpp.NPD_Required__c == 'true')) window.open('apex/sendInquirytoSAP?id={!Opportunity.Id}&rNPD=1&scontrolCaching=1','_self'); else window.open('apex/sendInquirytoSAP?id={!Opportunity.Id}&rNPD=0&scontrolCaching=1','_self'); } Commented Jun 15, 2016 at 9:23
  • else alert('Before trigger to SAP, Please select a SalesArea first.'); } else { alert('You cannot send Opportunity to SAP as no Opportunity Product is associated with it'); } } catch(e) { alert('An Error has Occurred. Error: ' + e); } } </script> <input type="button" style="width:100%;height:30px" value="Open" onclick="open()"/> </apex:page> Commented Jun 15, 2016 at 9:24
  • I HAVE WRITTEN ABOVE CODE IN VISUAL PAGE and made a action with selection of visualforce page of above page and make that action visible in salesforce1. Now , it open a new tab where Open button is shown and when i click that button nothing happen. Commented Jun 15, 2016 at 9:33
  • Can you help me in this and if there is some other solution can you tell me Commented Jun 15, 2016 at 9:35

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.