calling apex method from java script in Skuid

  • 2
  • Problem
  • Updated 1 year ago
  • Solved
in my model i have a 4 fields like VIN(vehicle Identification number), make, model,year. whenever i enter VIN number, i want to cal the apex method from javascript. for this how to cal the method from javascript. can any one give some sample code for javascrpt to cal Apex method when i enter VIN number
Photo of raj

raj

  • 840 Points 500 badge 2x thumb

Posted 3 years ago

  • 2
Photo of Hasantha Liyanage

Hasantha Liyanage

  • 1,446 Points 1k badge 2x thumb
In order to do this, first you need to have a global class and your method should be a webservice method:

global class TestClass {    
webservice static void testMethod(String testParameter) {
        ..Do your stuff..
    }
}

and then, you could call your apex method via javascript;

sforce.apex.execute( 
    'TestClass',
    'testMethod',
    {
        testParameter : 'VIN'
    }
);
Photo of rajasekhar reddy

rajasekhar reddy

  • 282 Points 250 badge 2x thumb
@Hasantha Liyanage Hi this is not firing the class , 

global class SkuidTest{
    webservice static ID createEmployee(String companyName) {
     
      Employment_Experience__c  emp=new Employment_Experience__c();
      emp.Name='SKUIDTEST001';
      emp.Company_Name__c=companyName;
      
      insert emp;
      
      return emp.Id;

    }
}

alert('vin check');var redult=sforce.apex.execute( 
    'SkuidTest',
    'createEmployee',
    {
        companyName : 'VIN'
    }
    );
  alert(redult);
 
  Is there anything we are missing in the approach
Photo of Hasantha Liyanage

Hasantha Liyanage

  • 1,446 Points 1k badge 2x thumb
Rajasekhar,

Please refer the link  to the post by Ant Belsham : Calling apex function will explain everything for you :)
Photo of Arne-Per Heurberg

Arne-Per Heurberg

  • 1,336 Points 1k badge 2x thumb
raj- you need to have added external resource for ajax tookit