function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

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.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);

syed furqan 1syed furqan 1
You Follow the same process as updating class using tooling api insted of using use ApexApexMember this in api call ApexPageMember