+ 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