Skip to content

Add fileds and custom action to layout #307

@nikhil270898

Description

@nikhil270898

Hi Team,

I’m trying to update page layouts by adding a custom action and some fields using the Metadata API. However, I'm encountering an issue where readMetadata() is returning null values, and I'm unable to proceed further.

Here’s the error I’m receiving: System.CalloutException: Web service callout failed: WebService returned a SOAP Fault: UNKNOWN_EXCEPTION: An unexpected error occurred. Please include this ErrorId if you contact support: 885255747-237006 (1807525792) faultcode=sf:UNKNOWN_EXCEPTION faultactor=

Below is the code snippet I’m using:

public static void addButton(){

    MetadataService.MetadataPort mdpService = createService();
   
    MetadataService.Layout objLayout = (MetadataService.Layout) mdpService.readMetadata('Layout',new String[] { 'Account-Account Layout' }).getRecords()[0];
    System.debug(JSON.serializePretty(mdpService.readMetadata('Layout',new String[] { 'Account-fno_sf_conn__Account Layout' }).getRecords()));
    System.debug(JSON.serializePretty(objLayout));
    if (objLayout.platformActionList == null) {
        objLayout.platformActionList = new MetadataService.platformActionList();
        objLayout.platformActionList.actionListContext = 'Record';
    }
    if (objLayout.platformActionList.platformActionListItems == null) {
        objLayout.platformActionList.platformActionListItems = new List<MetadataService.PlatformActionListItem>();
    }
    MetadataService.PlatformActionListItem objPlateformActionListItem = new MetadataService.PlatformActionListItem();
    objPlateformActionListItem.actionName ='Account.fno_sf_conn__Sync_with_FNO';
    objPlateformActionListItem.actionType = 'QuickAction';
    objPlateformActionListItem.sortOrder = 50;
    objPlateformActionListItem.subtype = null;
    objLayout.platformActionList.platformActionListItems.add(objPlateformActionListItem);
    
    //List<MetadataService.Metadata> lstLayoutsToUpdate = new List<MetadataService.Metadata>{objLayout};
    
    List<MetadataService.SaveResult> lstSaveResults = mdpService.updateMetadata(new MetadataService.Metadata[] { objLayout });
    
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions