You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am encountering an issue while attempting to retrieve layout metadata for the Quote object in my Salesforce org using the Metadata API. Despite providing the correct layout name ('Quote-Quote Layout') the metadata retrieval returns null values for all properties of the layout. And also facing an NullPointerException while adding custom fields to the page-layout.
Below is the MetadataAPI call , how I configured
`public static void addFieldsToPageLayout( String layoutName, List fieldApiNames) {
MetadataService.MetadataPort service = createMetadataService();
// Retrieve the existing layout metadata
//String layoutFullName = 'Quote.' + layoutName;
try{
MetadataService.Layout layoutMetadata = (MetadataService.Layout) service.readMetadata('Layout',new String[] { 'Quote-Quote Layout' }).getRecords()[0];
system.debug('layoutMetadata Begin: ' + layoutMetadata);
for (String fieldApiName : fieldApiNames) {
MetadataService.LayoutItem customFieldItem = new MetadataService.LayoutItem();
customFieldItem.field = fieldApiName;
// customFieldItem.behavior = MetadataService.LayoutBehavior.Edit;
// Add the layout item to the layout
layoutMetadata.layoutSections[0].layoutColumns[0].layoutItems.add(customFieldItem);
system.debug('layoutMetadata after adding: ' + layoutMetadata);
}
List<MetadataService.UpsertResult> results = service.upsertMetadata(new MetadataService.Metadata[] { layoutMetadata });
handleUpsertResults(results[0]);
system.debug('results: ' + results );
for (MetadataService.UpsertResult result : results) {
if (!result.success) {
for (MetadataService.Error error : result.errors) {
System.debug('Error message: ' + error.message);
}
}
}
} catch (Exception e){
system.debug('Exception at AddFieldMethod: ' + e);
}
}`
I am able to retrieve the layout metadata , As I added Namespace prefix to the layout Names , then it is working fine.
but now, I am not able to add a new layout section in that respective page layout. Here is my code
I am encountering an issue while attempting to retrieve layout metadata for the Quote object in my Salesforce org using the Metadata API. Despite providing the correct layout name ('Quote-Quote Layout') the metadata retrieval returns null values for all properties of the layout. And also facing an NullPointerException while adding custom fields to the page-layout.
Below is the MetadataAPI call , how I configured
`public static void addFieldsToPageLayout( String layoutName, List fieldApiNames) {
MetadataService.MetadataPort service = createMetadataService();
Layout details from WorkBench:
createdById: 0055h00000AYC1fAAH
createdByName: Pavan Kumar Panduru
createdDate: 2024-01-02T10:29:04.000Z
fileName: layouts/Quote-Quote Layout.layout
fullName: Quote-Quote Layout
id: 00h5h00000FhseFAAR
lastModifiedById: 0055h00000AYC1fAAH
lastModifiedByName: Pavan Kumar Panduru
lastModifiedDate: 2024-03-20T07:20:43.000Z
manageableState: unmanaged
namespacePrefix: SentinelEMSDEV
type: Layout
Layout metadata Debug statement:
layoutMetadata Begin: Layout:[Metadata.fullName=null, apex_schema_type_info=(http://soap.sforce.com/2006/04/metadata, true, false), customButtons=null, customButtons_type_info=(customButtons, http://soap.sforce.com/2006/04/metadata, null, 0, -1, false), customConsoleComponents=null, customConsoleComponents_type_info=(customConsoleComponents, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), emailDefault=null, emailDefault_type_info=(emailDefault, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), excludeButtons=null, excludeButtons_type_info=(excludeButtons, http://soap.sforce.com/2006/04/metadata, null, 0, -1, false), feedLayout=null, feedLayout_type_info=(feedLayout, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), field_order_type_info=(fullName, customButtons, customConsoleComponents, emailDefault, excludeButtons, feedLayout, headers, layoutSections, miniLayout, multilineLayoutFields, ...), fullName=null, fullName_type_info=(fullName, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), headers=null, headers_type_info=(headers, http://soap.sforce.com/2006/04/metadata, null, 0, -1, false), layoutSections=null, layoutSections_type_info=(layoutSections, http://soap.sforce.com/2006/04/metadata, null, 0, -1, false), miniLayout=null, miniLayout_type_info=(miniLayout, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), multilineLayoutFields=null, multilineLayoutFields_type_info=(multilineLayoutFields, http://soap.sforce.com/2006/04/metadata, null, 0, -1, false), platformActionList=null, platformActionList_type_info=(platformActionList, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), quickActionList=null, quickActionList_type_info=(quickActionList, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), relatedContent=null, relatedContent_type_info=(relatedContent, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), relatedLists=null, relatedLists_type_info=(relatedLists, http://soap.sforce.com/2006/04/metadata, null, 0, -1, false), relatedObjects=null, relatedObjects_type_info=(relatedObjects, http://soap.sforce.com/2006/04/metadata, null, 0, -1, false), runAssignmentRulesDefault=null, runAssignmentRulesDefault_type_info=(runAssignmentRulesDefault, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), showEmailCheckbox=null, showEmailCheckbox_type_info=(showEmailCheckbox, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), showHighlightsPanel=null, showHighlightsPanel_type_info=(showHighlightsPanel, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), showInteractionLogPanel=null, showInteractionLogPanel_type_info=(showInteractionLogPanel, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), showKnowledgeComponent=null, showKnowledgeComponent_type_info=(showKnowledgeComponent, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), showRunAssignmentRulesCheckbox=null, showRunAssignmentRulesCheckbox_type_info=(showRunAssignmentRulesCheckbox, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), showSolutionSection=null, showSolutionSection_type_info=(showSolutionSection, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), showSubmitAndAttachButton=null, showSubmitAndAttachButton_type_info=(showSubmitAndAttachButton, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), summaryLayout=null, summaryLayout_type_info=(summaryLayout, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), type=Layout, type_att_info=(xsi:type)]
CallOut Request:
SESSION_ID_REMOVEDLayoutQuote-Quote Layout15:09:15.617 (7627890828)
|readMetadata_element:[apex_schema_type_info=(http://soap.sforce.com/2006/04/metadata, true, false), field_order_type_info=(type_x, fullNames), fullNames=(Quote-Quote Layout), fullNames_type_info=(fullNames, http://soap.sforce.com/2006/04/metadata, null, 0, -1, false), type_x=Layout, type_x_type_info=(type, http://soap.sforce.com/2006/04/metadata, null, 1, 1, false)]::SOAPAction="" Accept=text/xml User-Agent=SFDC-Callout/60.0 SFDC_STACK_DEPTH=1 Content-Type=text/xml; charset=UTF-8
15:09:15.617 (7677640890)|
Getting Exception for my code:
e|Exception|true|false
"common.apex.runtime.impl.ExecutionException: Attempt to de-reference a null object"|
Expecting :
-> Able to read out the Metadata of the respective page layout.
-> Can able to add custom fields to that respective page layout.
The text was updated successfully, but these errors were encountered: