3

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.

2
  • One possible approach : If you already have a hosted app in Java, .NET etc that can make use of this sessionId to fire the updates, it could be embedded in web tab or exposed as a simple REST API. Commented Sep 9, 2012 at 15:15
  • Thanks, A, but I want to know how to get it into the Page record. What is the endpoint of the REST API call you're talking about? Commented Sep 9, 2012 at 23:00

1 Answer 1

3

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;
1
  • Thanks - I'll give that a shot. I'm hoping that it won't trigger test-running. And I'll need to look into error-handling. Commented Sep 10, 2012 at 5:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .