I just tried to implement Tooling API using REST API and did some basic callouts:
- create a Apex class
- creating a apex trigger
- editing apex class
- query a tooling api object
- delete a apex class
out of these 5 tries, i got succeed in three. By tooling api I was able to create a Apex class and delete a apex class and query a objects.
Rest of my tries:-
When I try to edit a apex class which i created before
it always comes with a error UNABLE TO ACCESS OBJECT FROM A CROSS REFERENCE ID
. I tried it in several ways changing letter cases, changing HTTP METHOD
but no method works. Setting correct configuration according to Salesforce Winter '14 tooling API guide but it shows same error UNABLE TO ACCESS OBJECT FROM A CROSS REFERENCE ID
. Why this error comes? Is some special access is required with these callout?
My code is
HttpRequest req = new HttpRequest();
req.setEndpoint('https://ap1.salesforce.com/services/data/v28.0/tooling/sobjects/ApexClass/'+oid+'?_HttpMethod=PATCH');
req.setHeader('Authorization', 'Bearer ' + UserInfo.getSessionID());
req.setHeader('Content-Type', 'application/json');
req.setBody('{"Name":"NewApexClass1","Body":"public class TheApexClass1 { // DO SOMETHING }"}');
req.setMethod('POST');
I am not sure what going wrong here.
After I tried to create ApexTrigger
but I stuck with TableEnumOrId
. If I give it a name e.g Lead
it says invalid object or...
and if I don't mention, it show MISSING FIELD
. I have read about creating ApexTrigger by Tooling API everywhere on internet but there is no answer for it. Work arounds are only that use simple REST API
to create a trigger. If anybody has some good reason, why this is error? please share some knowledge. If there are more issues regarding tooling API then please share.
Note: Already read all question regarding tooling api on this site , developerforce community and several other places.