+ Start a Discussion

Calling apex controller form javascript ?

Hi there,below is the code which calls my apex webservice conroller class and method,


when i execute below code I am getting "undefined", what is wrong with below code


var enrollmentEventId='{!Enrol_Event__c.Id}'
alert("test before calling calsss="+ enrollmentEventId);

var result = sforce.apex.execute("CSFcallExternalECWS","invokeExternalWs",{enrollmentEventId:enrollmentEventId});

alert("test after calling calsss="+ enrollmentEventId);

catch(err) {
txt="There was an error on this page.\n\n";
txt+="Error description: " + err.description+result+ "\n\n";
txt+="Click OK to continue.\n\n";


global classCSFcallExternalECWS



public  static   string enrolmentEventId;



webservice  static  string invokeExternalWs(string enrolmentEventIdValue)





Copied and pasted your code... it works verbatim (with a small change to object name for something I had in my dev org).

The only problem I could foresee is if this is a managed app, you must include the namespace of the package:

CSFcallExternalECWS should be namespace.CSFcallExternalECWS (where namespace is the namespace of the package).
Wizno @ ConfigeroWizno @ Configero

Was just about to say the same thing. Check the Namespace prefix that should be used. 


we don't have any namespace or any package, it is simple webservice apex class.


Wizno @ ConfigeroWizno @ Configero

Did you check your Apex Class List to see, or are you just assuming? I only ask because we need to completely rule it out. 


I also tried copy/pasting into my dev org, and had to add the Namespace prefix, and then it worked. 


I got it, ya i forgot about namespace, I didn’t look properly.

Wizno @ ConfigeroWizno @ Configero

Awesome! Can you mark sfdcfox's post as a solution and give both us some Kudos? ;-)