• michael_j_ramsey@hotmail.com
  • NEWBIE
  • 0 Points
  • Member since 2008

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
I have an Apex class that I want to call from a button.  But I can't figure out how to call it from a button.
Note: I have tested this code inside a trigger and it works fine.
 
My button code is just (obviously this is wrong):
sforce.apex.execute("MyHelloWorld","doKPI", {});
 
The class code:
global class MyHelloWorld {

  WebService static void doKPI() {

    INTEGER NUM = 10;

    KPI__c[] tblkpi;

    tblkpi = new KPI__c[NUM];

    for (integer i = 0; i < NUM; i++) {
      tblkpi[i] = new KPI__c(UserName__c='user '+i, Signed_Contracts__c = i);
    }
    insert tblkpi;
  }
}