classapex-codefrombodyattribute

Creating Apex Class dynamically


I have created Apex Trigger through passing this parameters and link:

  { 
  "Name" : "COTriggerEmp11", 
 "TableEnumOrId" : "employee__c",
  "Body" : "trigger COTriggerEmp11 on employee__c (before insert) {system.debug('Record Inserted');}"
}

 URL  :https://ap1.salesforce.com/services/data/v28.0/sobjects/ApexTrigger

Now I want to create Apex Trigger same way... Which parameters I need to pass And what should I write in Body section. I am have referred this doc also : http://www.salesforce.com/us/developer/docs/api/index.htm


Solution

  • I have tried by my own, got this solution and it is working fine. To create an Apex class dynamically do the following:

    { 
        "Name": "aaTest1",
        "Body": "public class aaTest1{}"
    }
    

    This will generate the class ID automatically. Now if you want to delete that class, you should pass that ID like this:

    https://ap1.salesforce.com/services/data/v28.0/sobjects/ApexClass/[Your Class ID]
    

    Maybe this will help somebody who is stuck like I was..Thanks.