Activity Forums Salesforce® Discussions How to execute Salesforce Apex from Custom button or Javascript ? Give Example

  • shariq

    Member
    September 22, 2018 at 6:27 pm

    It is possible using Ajax Toolkiit.

    global class myClass {
    webService static Id makeContact (String lastName, Account a) {
    Contact c = new Contact(LastName = lastName, AccountId = a.Id);
    return c.id;
    }
    }

    we can execute above method from javascript like :

    {!REQUIRESCRIPT("/soap/ajax/33.0/connection.js")}
    {!REQUIRESCRIPT("/soap/ajax/33.0/apex.js")}
    var account = sforce.sObject("Account");
    var id = sforce.apex.execute("myClass" , "makeContact",
    {lastName:"Smith", a:account});

  • Parul

    Member
    September 23, 2018 at 6:05 am

    USing remote action and action function

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos