开发者

I am generating an xml file in which i am fetching data from the custom setting i have made

public with sharing class xml4
{
public string x{get;set;}
public string c{get;set;}
List<ArtemisVC__Company_View_Extensions__c> mcs{get; set;}
public xml4 ()
{
    DOM.Document doc = new DOM.Document();
    dom.XmlNode Extensions = doc.createRootElement('Extensions',Null, Null);
    mcs=new List<ArtemisVC__Company_View_Extensions__c> ();
    mcs = ArtemisVC__Company_View_Extensions__c.getall().values();
    for(Integer i = 0 ; i <mcs.size(); i++)
    {
        dom.XmlNode Extension= Extensions.addChildElement('Extension',null , null);
        dom.XmlNode FieldName1= Extension.addChildElement('Name',null , null);
        FieldName1.addTextNode(mcs[i].Name);
        dom.XmlNode FieldName2=Extension.addChildElement('Url',null,null);
        //FieldName2.addTe开发者_StackOverflow中文版xtNode(mcs[i].ArtemisVC__Extension_URL__c);        
        dom.XmlNode FieldName3=Extension.addChildElement('Expand-Collapse-SOQL',null,null);
        FieldName3.addTextNode(mcs[i].Expand_Collapse_SOQL__c); 
        dom.XmlNode FieldName4=Extension.addChildElement('Order',null,null);
       // FieldName4.addTextNode(mcs[i].ArtemisVC__Order__c); 
        dom.XmlNode FieldName5=Extension.addChildElement('Height',null,null);
        //FieldName5.addTextNode(mcs[i].Height__c); 
        dom.XmlNode FieldName6=Extension.addChildElement('Width',null,null);
      //  FieldName6.addTextNode(mcs[i].Width__c); 
        dom.XmlNode FieldName7=Extension.addChildElement('ForCompanyType',null,null);
     //   FieldName7.addTextNode(mcs[i].Show_For_CompanyType__c); 
 dom.XmlNode FieldName8=Extension.addChildElement('PageOrRelatedListName',null,null);
       // FieldName8.addTextNode(mcs[i].PageOrRelatedListName__c); 
    }
    x = doc.toXmlString();
    c = 'text/xml#sachin.xml';
}
}

In the above code i am getting exception as System.NullPointerException: Argument 1 cannot be null

Class.ArtemisVC.xml4.: line 20, column 43 External entry point

Line 20 is FieldName3.addTextNode(mcs[i].Expand_Collapse_SOQL__c);

Please tell me how to pass the dynamic value in addTextNode().

Dom.XmlNode addTextNode(String text) - Creates a child text node for this node. The text argument can't have a null value.


I'm assuming in this case that "mcs[i].ArtemisVC__Extension_URL__c" is null, so you can use the ternary to avoid passing that into the function like so:

    FieldName3.addTextNode(mcs[i].Expand_Collapse_SOQL__c != null ? mcs[i].Expand_Collapse_SOQL__c : '');

If I've misunderstood, let me know!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜