Giter VIP home page Giter VIP logo

Comments (7)

afawcett avatar afawcett commented on July 27, 2024

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.

mahesh10811f0011 avatar mahesh10811f0011 commented on July 27, 2024

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.

afawcett avatar afawcett commented on July 27, 2024

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.

mahesh10811f0011 avatar mahesh10811f0011 commented on July 27, 2024

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.

afawcett avatar afawcett commented on July 27, 2024

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.

afawcett avatar afawcett commented on July 27, 2024

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.

afawcett avatar afawcett commented on July 27, 2024

Please take a look at this example for adding a field to a layout.

from apex-mdapi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.