Update Apex Page via Tooling API in Salesforce
Update Apex Page via Tooling API in Salesforce
What is Tooling Api?
Tooling api is for Building custom development tools for Force.com applications. Tooling API makes many development tasks easier.
When to use Tooling API?
When You want to add functionality to your existing development and integration tools or you want to build specialized development tools for a specific application or service.
Tooling API provides both SOAP and REST interfaces.
Use REST API if you’re using a language that isn’t strongly typed, like JavaScript. The Tooling REST API can be used just like the Force.com REST API.
To update an Apex Page:
Steps are below:
First we need to create Metadatacontainer object example:
Httprequest req =new HttpRequest();
req.setEndpoint(URL.getSalesforceBaseUrl().toExternalForm()+'/services/data/v28.0/tooling/sobjects/MetadataContainer/');
req.setHeader('Content-Type','application/json');
req.setHeader('Authorization','OAuth ' + UserInfo.getSessionId());
req.setMethod('POST');
req.setBody('{"Name":"pageMetadataContainer"}');
Http httpReq =new Http();
HttpResponse res = httpReq.send(req);
System.debug(res.getBody());
Next Create ApexPageMember.
below request with id : "MetadataContainerId" : "1dc90000000I6VGAA0" got from above request and "ContentEntityId" : "06690000005axNXAAY" is class id which need to update.Httprequest req =new HttpRequest();
req.setEndpoint(URL.getSalesforceBaseUrl().toExternalForm()+'/services/data/v28.0/tooling/sobjects/ApexPageMember/');
req.setHeader('Content-Type','application/json');
req.setHeader('Authorization','OAuth ' + UserInfo.getSessionId());
req.setMethod('POST');
req.setBody('{"MetadataContainerId":"1dc90000000I6VGAA0","ContentEntityId" : "06690000005axNXAAY","Body":"
Http httpReq =new Http();
HttpResponse res = httpReq.send(req);
System.debug(res.getBody());
Next create ContainerAsyncRequest object.
below request with id : "1dc90000000I6VGAA0" got from above request.Httprequest req =new HttpRequest();
req.setEndpoint(URL.getSalesforceBaseUrl().toExternalForm()+'/services/data/v28.0/tooling/sobjects/ContainerAsyncRequest/');
req.setHeader('Content-Type','application/json');
req.setHeader('Authorization','OAuth ' + UserInfo.getSessionId());
req.setMethod('POST');
req.setBody('{"MetadataContainerId" : "1dc90000000I6VGAA0", "isCheckOnly": "false"}');
Http httpReq =new Http();
HttpResponse res = httpReq.send(req);
System.debug(res.getBody());
Good one...
ReplyDeleteVery helpful.. :)
can you help i have to insert a account record using tooling api
ReplyDelete