Is it possible to edit the page layout section of custom/standard objects using meta data API in Apex class? I have created new field using meta data api , now i have to add that field to page layout section, how can i do that? i have referenced this https://github.com/financialforcedev/apex-mdapi/blob/master/apex-mdapi/src/classes/MetadataServiceExamples.cls to create fields.
2 Answers
Looking at the version history of MetadataService.cls, it looks like some manual work is needed for each inner class (type of metadata). So it is possible that if you modify MetadataService.Layout
following the same pattern, you will be able to insert a layout.
And you could then go on to see if an update that is just the addition of a layout item is possible. At first sight that seems unlikely: AFAIK there is no way to read just the existing layout back (in the form of the inner classes) so that you could then add your field and update it back.
The best way forward would be to contact the author Andrew Fawcett and discuss this API implementation with him and whether newer API's such a the Tooling API are more promising.
-
@AndrewFawcett in recent Spring14 PreRelease post has written about updating Layout. As per the post(if i understood correctly), this should happen automatically. Commented Apr 9, 2014 at 5:11
-
Looking at the code gist.github.com/afawcett/8108494 yes there is a readAndUpdateLayout example. So by early June when Spring '14 is fully rolled out and when Andrew releases his new API version it looks like you will be able to add a field to a layout over the API. (Not sure what you mean by "automatically".) So I think you already have the answer to your question.– Keith CCommented Apr 9, 2014 at 10:42
-
If we go by documentation of Metadata API, updating layout should be possible even in Winter 14. As I am new to Metadata API, & haven't been able to do it. And yes I do have an answer now.'automatically' - ignore that. Commented Apr 11, 2014 at 6:07
-
@AndrewFawcett, thanks for the detailed information. With this I am able to create Custom Object and Field but when I try to add the field on the page Layout using It gives me below error message "MetadataServiceExamples.MetadataServiceExamplesException: Error occured processing component null. Required field is missing: fullName (FIELD_INTEGRITY_EXCEPTION)." Commented Jul 30, 2014 at 6:19
-
guys- Is there some best practice of sort needed in updating Home Page Layouts? I have successfully executed metadata api call to Update Home Page Layouts and replaced a component with newer one, and I double checked that layouts are using the new components but when user logs in and loads his home page, the Old component is still showing up instead of new one. Is there something else also needed to be done here after update call? @AndrewFawcett– VarunCCommented Mar 19, 2015 at 9:35
In Summer 17 Metadata Access in Apex was added. It includes the ability to retrieve, create, or update page layouts directly from Apex.
See also: