Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How give Field accessable permission as Editable in pagelayouts Using metadata api? #41

Closed
mahesh10811f0011 opened this issue Jul 10, 2014 · 8 comments

Comments

@mahesh10811f0011
Copy link

Hi Andrew Fawcett,
I got following Error Related to addFieldToLayout() in your metadata api github related method.

System.CalloutException: Web service callout failed: WebService returned a SOAP Fault: null: Required field is missing: fullName faultcode=sf:UNKNOWN_EXCEPTION faultactor=
Error is in expression '{!createField}' in component apex:commandButton in page rajesh:createfields

Class.rajesh.MetadataService.MetadataPort.updateMetadata: line 8193, column 1
Class.rajesh.MetadataController11.addFieldToLayout: line 906, column 1
Class.rajesh.MetadataController11.createField: line 243, column 1
line 906:
handleSaveResults(
service.updateMetadata(
new MetadataService.Metadata[] { layout })[0]);
line 246:I called addFieldToLayout()

@afawcett
Copy link
Contributor

Did you specify the correct Layout name? In my example I had a Custom Object called Test__c with a standard Layout. Unless you also have a Test__c object you will need to change this.

@afawcett
Copy link
Contributor

There does look to be a bug in the readMetadata method when you don't give a valid metadata component name, such as the correct layout, it does not throw an exception. But instead returns an empty Layout, thus when you later call the updateMetadata method it rejects it because the fullName is empty. The solution to this in the meantime is to always make sure you pass a valid component name to the readMetadata method.

@mahesh10811f0011
Copy link
Author

Hi Andrew,
In another page i created Object name(Test) and fields name(TestField__c),one button and added like below and i added this code related methods also
public static void addFiedstolayout()
{
MetadataService.MetadataPort service = createService();
MetadataService.Layout layout =
(MetadataService.Layout) service.readMetadata('Layout',
new String[] { 'Test__c-Test Layout' }).getRecords()[0];
if(layout.layoutSections==null)
layout.layoutSections = new List<MetadataService.LayoutSection>();
MetadataService.LayoutSection newLayoutSection = new MetadataService.LayoutSection();
newLayoutSection.style = 'OneColumn';
System.debug('###newLayoutSection.style##########'+newLayoutSection.style);
MetadataService.LayoutColumn newLayoutColumn = new MetadataService.LayoutColumn();
MetadataService.LayoutItem newLayoutItem = new MetadataService.LayoutItem();
newLayoutItem.field = 'TestField__c';
System.debug('###newLayoutItem.field##########'+newLayoutItem.field);
newLayoutColumn.layoutItems = new List<MetadataService.LayoutItem> { newLayoutItem };
newLayoutSection.layoutColumns = new List<MetadataService.LayoutColumn> { newLayoutColumn };
layout.layoutSections.add(newLayoutSection);
handleSaveResults(
service.updateMetadata(
new MetadataService.Metadata[] { layout })[0]);
}
I got following error
System.CalloutException: Web service callout failed: WebService returned a SOAP Fault: null: Required field is missing: fullName faultcode=sf:UNKNOWN_EXCEPTION faultactor=
Error is in expression '{!addFiedstolayout}' in component apex:commandButton in page rajesh:createafieldusingmetadataapi

Class.rajesh.MetadataService.MetadataPort.updateMetadata: line 8163, column 1
Class.rajesh.MetadataController.addFiedstolayout: line 33, column 1
33 line:handleSaveResults(
service.updateMetadata(
new MetadataService.Metadata[] { layout })[0]);

IN DEBUGLOG LAYOUT Location like below
DEBUG|###layout##########Layout:[Metadata.apex_schema_type_info=(http://soap.sforce.com/2006/04/metadata, true, false), Metadata.field_order_type_info=(fullName), Metadata.fullName=null, Metadata.fullName_type_info=(fullName, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), 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://www.w3.org/2001/XMLSchema, string, 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), 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)]

@afawcett
Copy link
Contributor

I still think 'Test__c-Test Layout' is wrong this is why your getting this problem. Can you use Developer Workbench to list the layouts and confirm the full name is 'Test__c-Test Layout'. Also are you developing in a packaging org with the namespace set? This can change the name of the layout.

@mahesh10811f0011
Copy link
Author

Hi Andrew fawcett,
Here my object related Layout Information
Test__c-Test Layout:(full Name)

createdById: 005900000028CF8AAM
createdByName: rajesh
createdDate: 2014-07-10T05:18:43.000Z
fileName: layouts/Test__c-Test Layout.layout
fullName: Test__c-Test Layout
id: 00h9000000OMWm3AAH
lastModifiedById: 005900000028CF8AAM
lastModifiedByName: rajesh
lastModifiedDate: 2014-07-10T05:18:43.000Z
manageableState: unmanaged
namespacePrefix: rajesh
type: Layout

@afawcett
Copy link
Contributor

So your in a namespace org by the looks of this? Your namespace is set to rajesh under the Create > Packages page, is this correct?

If so, i think the full name needs to include the namespace, take a look at this issue #32. Especially this last comment...

I solved this. It works if I try 'CA10__CaAwsCloudTrailEvent__c-CA10__AWS CloudTrail Event Layout'. btw listMetadata returns 'CA10__CaAwsCloudTrailEvent__c-AWS CloudTrail Event Layout' (without prefix).

Maybe you need to provide...

Test__c-rajesh__Test Layout   

Or try...

rajest__Test__c-rajesh__Test Layout   

@mahesh10811f0011
Copy link
Author

Hi Andrew Fawcett,
That is Andrew Fawcett
Super Sir.................

@afawcett
Copy link
Contributor

Welcome! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants