function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
DivyanshD SinghDivyanshD Singh 

Add two columns in a section of Layout by Metadata Apex

Here is my code for a separate section and a column.I need to 2 two columns as i have many field to show on that section of layout.
Can anyone help how to divide a section in two columns by apex.I am using Metadata API currently.
if(layout.layoutSections==null)
            layout.layoutSections = new List<MetadataService.LayoutSection>();
        MetadataService.LayoutSection newLayoutSection = new MetadataService.LayoutSection();
        newLayoutSection.customLabel = true;
        newLayoutSection.detailHeading = true;
        newLayoutSection.editHeading = true;
        newLayoutSection.label = 'Keyword fields';
        newLayoutSection.style = 'TwoColumnsLeftToRight';}

 
jit chakjit chak
Faisu (https://www.ontoolfactory.co/2019/11/Mr-Faisu-Biography.html) is an actor, model, fashion blogger, YouTuber and Tik-Tok star. He is primarily known for his amazing Tik-Tok videos. Born on 5 October 1994, he did his schooling from IES New English School in Bandra, Mumbai. He completed his graduation from Rizvi College of Arts, Science and Commerce
jit chakjit chak
Arishfa Khan (https://www.ontoolfactory.co/2019/11/Arishfa-Khan-Biography.html) (born April 3, 2003) is an Indian Actress, Dancer, Model, YouTuber, Instagram Star, Vlogger and Social Media Influencer from Shahjahanpur, Uttar Pradesh (India). She moved to Mumbai to try her luck in the TV shows. As per Wikipedia, Arishfa offered a lead role of Gunjan in “Ek Veer Ardaas… Veera” (2012)
DivyanshD SinghDivyanshD Singh
I dont think the answer you are putting has any relevance here. You ppl are trash to this community.
Annu ChoudharyAnnu Choudhary
Hi Divyansh,
Please try this one.
Select the best answer if it is working for you.
 
public static void runUpdateLayouts(){ 
     // 'Give the full name of layout Like : objectapiname-layoutname
    Metadata.Layout la = getLayout('Test__c-Test Layout'); 
        Metadata.LayoutSection sec = new Metadata.LayoutSection();
        sec.customLabel = true;
        sec.detailHeading = true;
        sec.editHeading = true;
        sec.label = 'TestLayout';
        sec.style = metadata.LayoutSectionStyle.TwoColumnsLeftToRight;
        Metadata.LayoutColumn col1 = new Metadata.LayoutColumn();
		Metadata.LayoutColumn col2 = new Metadata.LayoutColumn();

        Metadata.LayoutItem layoutField = new Metadata.LayoutItem();
        layoutField.field = 'Parent_RecordId__c';
        layoutField.behavior = metadata.UiBehavior.Readonly;
        col1.layoutItems.add(layoutField);

        Metadata.LayoutItem layoutField2 = new Metadata.LayoutItem();
        layoutField2.field = 'frgAccount__c';
        layoutField2.behavior = metadata.UiBehavior.Readonly;
        
        col2.layoutItems.add(layoutField2);
        sec.layoutColumns.add(col2);
        la.layoutSections.add(sec);

        Metadata.DeployContainer dc = new Metadata.DeployContainer();
        dc.addMetadata(la);

        Id jobid = Metadata.Operations.enqueueDeployment(dc,null);

}
  public static Metadata.Layout getLayout(String layoutName){
      System.debug(layoutName);
        List<String> layoutList = new List<String>{layoutName};
        List<Metadata.Metadata> components = Metadata.Operations.retrieve(Metadata.MetadataType.Layout,layoutList);
        return (Metadata.Layout)components[0];
    }

Please select the best answer if it is working for you.

Thanks,
Annu Choudhary