We have Layout Read-only fields to be added. Seems like a bug, when we try to add read-only fields they become read-write on layout. Please see below example.

public class metadatatest {
    public static void runUpdateLayouts(){        
        Metadata.Layout la = getLayout('Account-Account Layout');

        Metadata.LayoutSection sec = new Metadata.LayoutSection();
        sec.customLabel = true;
        sec.detailHeading = true;
        sec.editHeading = true;
        sec.label = 'Custom fields';
        sec.style = metadata.LayoutSectionStyle.OneColumn;

        Metadata.LayoutColumn col1 = new Metadata.LayoutColumn();

        Metadata.LayoutItem layoutField = new Metadata.LayoutItem();

        layoutField.field = 'testfield__c';
        layoutField.behavior = metadata.UiBehavior.Readonly;



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

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

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

Above code will add testfield__c field to Account standard layout. But it shows as Readonly in Layout editor. But in Account both view and edit modes it's read-write.

  • 1
    The "Edit read-only fields" permission is set on the System Administrator profile. Have you tested under a different profile that does not have that permission set?
    – Keith C
    Commented Jun 19, 2017 at 8:08

1 Answer 1


Thanks @Keith. This is a standard feature of a System Administrator profile. All Salesforce System Admins can edit read only fields. Also, standard Profiles are not editable at all.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .