Find your content:

Search form

You are here

Simple API call to update a Visualforce Page?

 
Share

I want to build an integration that would overwrite/update (and eventually create) a Visualforce page. I'm not sure if just updating a VF page makes all the tests fire, as I can edit VF pages in Production, so ideally it would just overwrite the text in the Page record.

I know there's a Metadata API, but I don't want to have to use ant and all that just to write to a Page. If I have to do that, is there a simple way to write to that object without a lot of hassle?

In the scenario, I would already have a session ID, so authorization isn't a problem.


Attribution to: DavidSchach

Possible Suggestion/Solution #1

I just did a quick test and was able to use the ApexPage object that is exposed via the PartnerAPI to update the Visualforce page Markup property. You will need the "Customize Application" permission to do this.

Exactly how this is expressed in code will depend on your environment. Basically, you create an sObject with the type ApexPage and the Id of the Visualforce page in question. Then set the new Markup field value in any. Finally, call the Partner API update method to set the new value.

Hypothetically, if you could do this in Apex it would look something like the following. Note that this doesn't actually work from Apex. You will get a "DML not allowed on ApexPage line:3" message. The intention is to show the objects and fields that you would be working with via the Partner API.

ApexPage testPage = [Select Id, Markup from ApexPage where Id = '066700000000005'];
testPage.Markup = '<apex:page ><h1>Hello World</h1></apex:page>';
update testPage;

Attribution to: Daniel Ballinger
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/1277

My Block Status

My Block Content