質問

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

役に立ちましたか?

解決

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.

他のヒント

I wanted to take this further and generate a larger Apex class via automation. Doing so I found some special considerations due to use of JSON to pass the code that I wanted to note to help others potentially if they want to do same.

First of all I had to escape use of backslashes (replace occurrences of \ with \\). In fact, because I was coding in Apex (creating a Salesforce class from within Salesforce), I had to even escape them in my source code that was massaging the class code so my apex statement became...

string bodystring = batchCode.replace('\\','\\\\');

And then I also needed to escape the newline characters in the code (replace occurrences of \n with \\n).

Other source code I was working with had tab characters in it and those caused issues with JSON deserialization. So added mycode.replace('\t',' ') to clean them out of the code.

With those adjustments to my code I was able to create Apex classes via automation.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top