1

I am trying to migrate classes from an older API version to a moderately higher version, while doing so I came across a JS button which calls an apex method and creates a record. This has stopped working when I change the version number of the class from 26 to 40 and I get a error message as show in the screenshot below. But when I revert the version back to 26 it works well. I also tried to check the considerations and forward compatibility of these JS buttons but I wasn't able to find any article on it. I have also added the code for your reference. Can someone let me know how to fix it?

SOAP Fault error message

JS Button :
{!REQUIRESCRIPT("/soap/ajax/40.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/40.0/apex.js")}

var oppId= "{!Opportunity.Id }";
var accId= "{!Opportunity.AccountId}";
var url = parent.location.href;


//sforce.debug.trace=true;

var status = sforce.apex.execute("NewQuoteRequestHelper2", "createResquest", {a:oppId, b:accId});
//sforce.debug.trace=true;
if( status == 'true'){
parent.location.href = url;
}

Apex class :
global class NewQuoteRequestHelper2{
         
         webservice static string createResquest (Id oppId, Id accId){
              string ret = 'false';
              //Opportunity o= [SELECT AccountId, ContactId, Id, _Name__c, Status, Subject, Type, Date_Due__c, Origin FROM Case where id=: oppId];
              case c= new case();
              c.AccountId= accId;
              c.Opportunity_Name__c= oppId;
              c.Status= 'Not Started';
              c.Subject='Please Generate Quote'; 
              //c.Type="Request Quote" ;
              c.Date_Due__c= system.today();
              c.Origin='Opportunity';
              insert c;
              ret ='true';
              return ret;
         }
}


2
  • 1
    Why are you passing data in the format {a:oppId, b:accId} and not {oppId:oppId, accId:accId}?
    – TSmith
    Feb 22, 2022 at 12:03
  • Actually, the button was coded that way and it was working. I changed the parameter names to oppId and accId and they are working now, Thank you. Feb 22, 2022 at 13:53

1 Answer 1

1

The AJAX toolkit allowing calls to Apex through sforce.apex.execute() must be used with the following parameters.

sforce.apex.execute(ClassName, MethodName, InputData). The execute method takes primitive data types, sObjects, and lists of primitives or sObjects. Here, InputData can be an empty object OR an object defining key-value pairs where the key always matches the Apex method input parameter name.

NewQuoteRequestHelper2.createResquest (Id oppId, Id accId) has 2 input parameters therefore the webservice request should pass an object structured as:

{
   oppId : <value>,
   accId : <value>
}

Client side call then be var status = sforce.apex.execute("NewQuoteRequestHelper2", "createResquest",{oppId:oppId, accId:accId});.

You must log in to answer this question.

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