You need to sign in to do that
Don't have an account?
Update account page layout programatically
Hello Everyone,
I am trying to update accounts page layout with a custom link. I managed to create a custom link which is great. Now I am able to retrieve the page layout through retrieve call. Which gives a zip file, is there a way I could update the layout through the Metadata API? So far I have tried this,
Layout co = new Layout();
co.setFullName("Account-Trial2");
LayoutSection layoutSection = new LayoutSection();
layoutSection.setStyle(LayoutSectionStyle.CustomLinks);
layoutSection.setCustomLabel(true);
layoutSection.setLabel("Custom Links");
LayoutColumn layoutColumn = new LayoutColumn();
LayoutItem[] layoutItemList = new LayoutItem[1];
LayoutItem layoutItem = new LayoutItem();
layoutItem.setCustomLink("Infosmart_Results");
layoutItemList[0] = layoutItem;
layoutColumn.setLayoutItems(layoutItemList);
LayoutColumn[] layoutColumnList = new LayoutColumn[1];
layoutColumnList[0] = layoutColumn;
layoutSection.setLayoutColumns(layoutColumnList);
LayoutSection[] layoutSectionList = new LayoutSection[1];
layoutSectionList[0] = layoutSection;
co.setLayoutSections(layoutSectionList);
UpdateMetadata updateMetadata = new UpdateMetadata();
updateMetadata.setMetadata(co);
updateMetadata.setCurrentName("Trial"); // co.getFullName();
This code leads to the following exception
Error status code: FIELD_INTEGRITY_EXCEPTION
Error message: Layout must contain an item for required layout field: Name
The object state is Error
What am I missing here. Any help will be greatly appreciated.
Regards
Ananth Chellathurai
Hi All,
Managed to code this some how. Using the retrieve call got all layout files parsed through it using dom4j and updated a new custom link to it. Make sure to remove the emply <layoutColumn\> while adding a new link.
Also the <style> has to be the last element in the layout section.
Regards
Ananth Chellathurai
Blog
All Answers
Hello Simon,
Thanks for the reply. How do I read the current layout? In the metadata API read is only through retrieve() call I believe. Which brings a zip file, do I have to read the layout file from the zip? Can you help me with an URL or sample code?
Thanks in advance.
Ananth Chellathurai
Blog
Hi All,
Managed to code this some how. Using the retrieve call got all layout files parsed through it using dom4j and updated a new custom link to it. Make sure to remove the emply <layoutColumn\> while adding a new link.
Also the <style> has to be the last element in the layout section.
Regards
Ananth Chellathurai
Blog
Hi Ananth,
Hopefully you will still be able to help.
Could you please upload a version of this working so that we have a complete reference to how you completed the task.
Thanks,
Adrian