+ Start a Discussion
bobnunny1bobnunny1 

Build Automated Metadata Updates for Multi-Org Deployment

I'm trying to complete the trail module named in the subject, but I'm getting an error of:
Challenge Not yet complete... here's what's wrong: 
Couldn't find newField.behavior set to 'Metadata.UiBehavior.Edit', or newField.field set to 'AMAPI__Apex_MD_API_Twitter_name__c' or method doesn't return 'layoutMetadata'. Please double-check the instructions

Everything looks right to me in the class.  I can't use the namespace they provide because it's already taken.   Earlier in the exercise, it tells you to use your own namespace which I've done.  Can anyone see what's wrong?
 
public class UpdateContactPageLayout {
    // Add custom field to page layout
    
    public Metadata.Layout addLayoutItem () {
        
        // Retrieve Contact layout and section 
        List<Metadata.Metadata> layoutsList = 
            Metadata.Operations.retrieve(Metadata.MetadataType.Layout, 
            new List<String> {'Contact-Contact Layout'});
        Metadata.Layout layoutMetadata = (Metadata.Layout) layoutsList.get(0);
        Metadata.LayoutSection contactLayoutSection = null;
        List<Metadata.LayoutSection> layoutSections = layoutMetadata.layoutSections;
        for (Metadata.LayoutSection section : layoutSections) {
            
            if (System.equals(section.label, 'Additional Information')) {
                contactLayoutSection = section;
                break;
            }
        }
        
        // Add the field under Contact info section in the left column
        List<Metadata.LayoutColumn> contactColumns = contactLayoutSection.layoutColumns;     
        List<Metadata.LayoutItem> contactLayoutItems = contactColumns.get(0).layoutItems;
        
        // Create a new layout item for the custom field
        Metadata.LayoutItem newField = new Metadata.LayoutItem();
        newField.behavior = Metadata.UiBehavior.Edit;
        newField.field = 'BOBN_TRAILHEAD__Apex_MD_API_Twitter_name__c';
        contactLayoutItems.add(newField);
        
        return layoutMetadata;
    }
}

 
Best Answer chosen by bobnunny1
Bill DodsonBill Dodson
Mine is exactly like yours except line 28 I have as:

newField.field = 'AMAPI__Apex_MD_API_Twitter_name__c';

Challenge completed for me.

All Answers

Bill DodsonBill Dodson
Mine is exactly like yours except line 28 I have as:

newField.field = 'AMAPI__Apex_MD_API_Twitter_name__c';

Challenge completed for me.
This was selected as the best answer
bobnunny1bobnunny1
Thanx.  Worked this time.  Must've made a typo originally.
KapavariVenkatramanaKapavariVenkatramana
@Bill Dodson
Yes sir It Worked..thanks