You need to sign in to do that
Don't have an account?
pinki
update visualforce page from tooling API
How can we update a visualforce page from a class through Tooling API? I am using the below code which creates a Visualforce page called 'TestPageFromRest'. If I want to conditionally update the page next time, how can I do it? Please share the code if someone knows.
public class ToolingNewPage{
private static String baseUrl = URL.getSalesforceBaseUrl().toExternalForm()
+ '/services/data/v28.0/tooling/';
public static void createPage() {
String salesforceHost = System.Url.getSalesforceBaseURL().toExternalForm();
String url = salesforceHost + '/services/data/v29.0/sobjects/ApexPage';
HttpRequest req = new HttpRequest();
req.setMethod('POST');
req.setEndpoint(url);
req.setHeader('Content-type', 'application/json');
req.setHeader('Authorization', 'Bearer ' + UserInfo.getSessionId());
//for controllerType = >0 -- no controller
req.setBody('{"Name" : "TestPageFromRest","Markup" : "<apex:page>hello</apex:page>","ControllerType" : "0","MasterLabel":"TestPageFromRest","ApiVersion":"29.0"}');
//for controllerType => 1 -- Standard controller + extensions
//req.setBody('{"Name" : "TestPageFromRestCase","Markup" : "<apex:page standardController=\'case\' extensions=\'displaycase\'>hello</apex:page>","ControllerType" : "1","MasterLabel":"TestPageFromRestCase","ApiVersion":"29.0"}');
//for controllerType => 3 --custom Controller
//req.setBody('{"Name" : "TestPageFromRestCase1","Markup" : "<apex:page controller=\'displaycase\'>hello</apex:page>","ControllerType" : "3","MasterLabel":"TestPageFromRestCase1","ApiVersion":"29.0"}');
Http http = new Http();
HTTPResponse res = http.send(req);
System.debug(res.getBody());
}}
public class ToolingNewPage{
private static String baseUrl = URL.getSalesforceBaseUrl().toExternalForm()
+ '/services/data/v28.0/tooling/';
public static void createPage() {
String salesforceHost = System.Url.getSalesforceBaseURL().toExternalForm();
String url = salesforceHost + '/services/data/v29.0/sobjects/ApexPage';
HttpRequest req = new HttpRequest();
req.setMethod('POST');
req.setEndpoint(url);
req.setHeader('Content-type', 'application/json');
req.setHeader('Authorization', 'Bearer ' + UserInfo.getSessionId());
//for controllerType = >0 -- no controller
req.setBody('{"Name" : "TestPageFromRest","Markup" : "<apex:page>hello</apex:page>","ControllerType" : "0","MasterLabel":"TestPageFromRest","ApiVersion":"29.0"}');
//for controllerType => 1 -- Standard controller + extensions
//req.setBody('{"Name" : "TestPageFromRestCase","Markup" : "<apex:page standardController=\'case\' extensions=\'displaycase\'>hello</apex:page>","ControllerType" : "1","MasterLabel":"TestPageFromRestCase","ApiVersion":"29.0"}');
//for controllerType => 3 --custom Controller
//req.setBody('{"Name" : "TestPageFromRestCase1","Markup" : "<apex:page controller=\'displaycase\'>hello</apex:page>","ControllerType" : "3","MasterLabel":"TestPageFromRestCase1","ApiVersion":"29.0"}');
Http http = new Http();
HTTPResponse res = http.send(req);
System.debug(res.getBody());
}}
syed furqan 1
You Follow the same process as updating class using tooling api insted of using use ApexApexMember this in api call ApexPageMember