2

Can I add Custom field to Page Layout via Partner or Metadata API ? Any Example would be great

1

This is definitely possible through the Metadata API. The Metadata API is actually what drives all deployments. You are actually looking for the Layout which:

Represents the metadata associated with a page layout.

Essentially, when doing a pull on your page layout's metadata, you will get something like below returned as XML:

<?xml version="1.0" encoding="UTF-8"?>
<Layout xmlns="http://soap.sforce.com/2006/04/metadata">
   <customConsoleComponents>
    <primaryTabComponents>
       <container>
           <region>left</region>
          <style>Stack</style>
          <unit>Pixel</unit>
          <width>101</width>
          <sidebarComponent>
                <width>60</width>
                <page>simplepage1</page>
                <unit>Percentage</unit>
          </sidebarComponent>
          <sidebarComponent>
                <width>40</width>
                <page>Hello_World</page>
                <unit>Percentage</unit>
          </sidebarComponent>
       </container>
    </primaryTabComponents>
    <subtabComponents>
       <component>
          <location>top</location>
          <visualforcePage>ConsoleComponentPage2</visualforcePage>
          <height>200</height>
       </component>
    </subtabComponents>
   </customConsoleComponents>
    <customButtons>ButtonLink</customButtons>
    <layoutSections>
        <editHeading>true</editHeading>
        <label>Information</label>
        <layoutColumns>
            <layoutItems>
                <behavior>Required</behavior>
                <field>Name</field>
            </layoutItems>
            <layoutItems>
                <height>180</height>
                <scontrol>LayoutSControl</scontrol>
                <showLabel>true</showLabel>
                <showScrollbars>true</showScrollbars>
                <width>50%</width>
            </layoutItems>
            <layoutItems>
                <reportChartComponent>
                   <contextFilterableField>CUST_ID</contextFilterableField>
                   <includeContext>true</includeContext>
                   <reportName>Open_Accounts_by_Cases</reportName>
                   <showTitle>false</showTitle>
                   <size>LARGE</size>
                <reportChartComponent>
            </layoutItems>
        </layoutColumns>
        <layoutColumns>
            <layoutItems>
                <behavior>Edit</behavior>
                <field>OwnerId</field>
            </layoutItems>
            <layoutItems>
                <behavior>Edit</behavior>
                <field>CurrencyIsoCode</field>
            </layoutItems>
        </layoutColumns>
        <style>TwoColumnsTopToBottom</style>
    </layoutSections>
    <layoutSections>
        <editHeading>true</editHeading>
        <label>System Information</label>
        <layoutColumns>
            <layoutItems>
                <behavior>Readonly</behavior>
                <field>CreatedById</field>
            </layoutItems>
            <layoutItems>
                <behavior>Readonly</behavior>
                <field>Alpha1__c</field>
            </layoutItems>
        </layoutColumns>
        <layoutColumns>
            <layoutItems>
                <behavior>Readonly</behavior>
                <field>LastModifiedById</field>
            </layoutItems>
            <layoutItems>
                <behavior>Edit</behavior>
                <field>TextArea__c</field>
            </layoutItems>
        </layoutColumns>
        <style>TwoColumnsTopToBottom</style>
    </layoutSections>
    <layoutSections>
        <customLabel>true</customLabel>
        <detailHeading>true</detailHeading>
        <label>Custom Links</label>
        <layoutColumns>
            <layoutItems>
                <customLink>CustomWebLink</customLink>
            </layoutItems>
        </layoutColumns>
        <style>CustomLinks</style>
    </layoutSections>
    <relatedContent>
        <relatedContentItems>
            <layoutItem>
                <component>sfa:socialPanel</component>
            </layoutItem>
        <relatedContentItems>
    </relatedContent>
    <miniLayoutFields>Name</miniLayoutFields>
    <miniLayoutFields>OwnerId</miniLayoutFields>
    <miniLayoutFields>CurrencyIsoCode</miniLayoutFields>
    <miniLayoutFields>Alpha1__c</miniLayoutFields>
    <miniLayoutFields>TextArea__c</miniLayoutFields>
    <miniRelatedLists>
        <relatedList>RelatedNoteList</relatedList>
    </miniRelatedLists>
    <relatedLists>
        <fields>StepStatus</fields>
        <fields>CreatedDate</fields>
        <fields>OriginalActor</fields>
        <fields>Actor</fields>
        <fields>Comments</fields>
        <fields>Actor.Alias</fields>
        <fields>OriginalActor.Alias</fields>
        <relatedList>RelatedProcessHistoryList</relatedList>
    </relatedLists>
    <relatedLists>
        <relatedList>RelatedNoteList</relatedList>
    </relatedLists>
</Layout>

You will have to go through it and play with it a bit, but you should definitely be able to edit how the fields are laid out by modifying that XML and using the Force.com Ant Migration Tool.

  • Thanks Jesse. Sorry for late response but I am not able to do that via Layout object. Can you provide some code example ? – Mehul Mar 3 '14 at 14:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.