Comments (7)
So a NullPointerExceptions means that one of the following is null....
layout
layout.layoutSections[0]
layout.layoutSections[0]. layoutColumns[0]
layout.layoutSections[0]. layoutColumns[0].layoutItems
Have done any debug to find out out which it is?
My thinking is you will have to put some null pointer protection in your code to check each of these and take appropriate action, such as add a new section or column as required perhaps?
from apex-mdapi.
Hi afawcett,
updateFieldpageLayout() In this method the above code only i was using.I don't use below all are in any place in my program.
layout
layout.layoutSections[0]
layout.layoutSections[0]. layoutColumns[0]
layout.layoutSections[0]. layoutColumns[0].layoutItems
How to assign layoutsections and layoutcolumns without null?
help me...
from apex-mdapi.
I have not had time to test it, but please try this...
// Add a new section, new column and new layout item for the field
if(layout.layoutSections==null)
layout.layoutSections = new List<MetadataService.LayoutSection>();
MetadataService.LayoutSection newLayoutSection = new MetadataService.LayoutSection();
MetadataService.LayoutColumn newLayoutColumn = new MetadataService.LayoutColumn();
MetadataService.LayoutItem newLayoutItem = new MetadataService.LayoutItem();
newLayoutItem.field = 'TestField__c';
newLayoutColumn.layoutItems = new List<MetadataService.LayoutItem> { newLayoutItem };
newLayoutSection.layoutColumns = new List<MetadataService.LayoutColumn> { newLayoutColumn };
layout.layoutSections.add(newLayoutSection);
from apex-mdapi.
Hi ,
Here I added like this
public void updateFieldpageLayout()
{
MetadataService.MetadataPort service = createService();
List<MetadataService.Metadata> myCustomlayoutList = new List<MetadataService.Metadata>();
// Read the Layout
MetadataService.Layout layout =
(MetadataService.Layout) service.readMetadata('Layout',
new String[] { 'rajesh__+ strFieldName+__c-strFieldName Layout' }).getRecords()[0];
if(layout.layoutSections==null)
{ layout.layoutSections = new List<MetadataService.LayoutSection>();
MetadataService.LayoutSection newLayoutSection = new MetadataService.LayoutSection();
MetadataService.LayoutColumn newLayoutColumn = new MetadataService.LayoutColumn();
MetadataService.LayoutItem newLayoutItem = new MetadataService.LayoutItem();
newLayoutItem.field = 'rajesh__'+ strFieldName+'__c.'+Field2+'__c';
newLayoutColumn.layoutItems = new List<MetadataService.LayoutItem> { newLayoutItem };
newLayoutSection.layoutColumns = new List<MetadataService.LayoutColumn> { newLayoutColumn };
layout.layoutSections.add(newLayoutSection);
}
// Here add your field by finding or adding the layout section and columns etc…
MetadataService.LayoutItem LayoutItem = new MetadataService.LayoutItem();
LayoutItem.field = 'rajesh__'+ strFieldName+'__c.'+Field2+'__c';
// This code assumes the first section, first column of the layout
layout.layoutSections[0]. layoutColumns[0].layoutItems.add(LayoutItem);
// Update the Layout
handleSaveResults(
service.updateMetadata(
new MetadataService.Metadata[] { layout })[0]);
}
i got following error .
System.CalloutException: Web service callout failed: WebService returned a SOAP Fault: '' is not a valid value for the enum 'LayoutSectionStyle' faultcode=soapenv:Client faultactor=
Error is in expression '{!doupdatapagelayout}' in component apex:commandButton in page rajesh:readandupdatelayout
help me.......
from apex-mdapi.
I did not have chance to test this for you. If you refer to the Metadada API Developers Guide you can see what value to place in LayoutSectionStyle property. You can also find if you download the WSDL and view it, the enum values for this property that way. Please spend some time to review documentation, this library is a wrapper around the standard Salesforce Metadata API so it's documentation is very useful. Today I am out with my family and it is hard to respond quickly. Thanks.
from apex-mdapi.
I would also strongly recommend by the nature of your questions taking more time to learn apex programming basics like handling lists and searching lists. The Apex Developer Guide has some good sections for this. Good luck and I will try to help as much as I can, but often your questions don't make much sense to me, I do keep trying so long as you also try to help by reading documentation as much as possible.
from apex-mdapi.
Please take a look at this example for adding a field to a layout.
from apex-mdapi.
Related Issues (20)
- MetadataServiceExamples outdated
- Test Class For MetadatadeolpyController Class
- Help article to use named credentials with wrapper has been removed HOT 1
- Generate an Apex from WSDL
- GlobalValueSetTranslation HOT 2
- Update search layout task, event, activity HOT 1
- System.CalloutException: Web service callout failed: Unable to parse callout response. Apex type not found for element customizeSetup
- Apex Wrapper Metadata API Takes Time to Reflect the Change
- Can't create in production org
- Can't create a sharing rule HOT 2
- GlobalValueSetTranslation
- Can we create ApexClass natively? Any Example? HOT 1
- UserInfo.getSessionId() makes this unusable in packaged code HOT 2
- How do we update multiple profiles at once?
- LightningComponentBundle (LWC): reading/creating/updating
- Creating Apex Trigger
- Creating a MultiPicklist HOT 2
- System.CalloutException: Web service callout failed: Unable to parse callout response. Apex type not found for element includeRecordsOwnedByAll
- How To get Picklist Value according to record type for a custom object HOT 3
- Can anyone suggest on how to read the flexipage? HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from apex-mdapi.