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
louisa barrett 7louisa barrett 7 

Get field values from metadata.layoutItem

I was wondering if anyone knew of a way to get the values of the field within a page layout section. Within a trigger I want to grab the fields and values assigned, that are within a particular section, and then calculate an average based on the field values.
I've got the field names and was hoping there was a way I could get the value.
 
private void setFusionScore(Training_Self_Assessment__c[] newSAs)
    {
        for(Training_Self_Assessment__c tsa : newSAs)
        {
            system.debug('TSA trigger');
            List<Metadata.Metadata> layouts = 
                Metadata.Operations.retrieve(Metadata.MetadataType.Layout, 
                                             new List<String> {'Training_Self_Assessment__c-Training Record Layout'});
            system.assertEquals(1, layouts.size());
            Metadata.Layout layoutMd = (Metadata.Layout)layouts.get(0);
            for (Metadata.LayoutSection section : layoutMd.layoutSections) 
            {
                if(section.label == 'Fusion')
                {  
                    for (Metadata.LayoutColumn column : section.layoutColumns) 
                    {
                        if (column.layoutItems != null) 
                        {
                            for (Metadata.LayoutItem item : column.layoutItems) 
                            {
                                system.debug('Field Name = ' + item.field);
                                system.debug('Field Value = ' + item.??);
                            }
                        }
                    }
                }
            }
        }         
    }

Many thanks