function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
sai Addagarlasai Addagarla 

Argument cannot be null. Error is in expression '{!callme}' in component <apex:commandButton> in page vf_xml_eg1_xmldynamicaccount: Class.Eg1_XML_Dserfromfile.callme: line 7, column 1 An unexpected error has occurred. Your development organization has be

The following Error I'm getting------------>
===============================
Argument cannot be null.
Error is in expression '{!callme}' in component <apex:commandButton> in page vf_xml_eg1_xmldynamicaccount: Class.Eg1_XML_Dserfromfile.callme: line 7, column 1
An unexpected error has occurred. Your development organization has been notified.

The following CLASS used------------>
===============================
public class Eg1_XML_Dserfromfile 
{
    public Blob xmlfile {set;get;}
    public void callme()
    {
        list<Account> accounts = new list<Account>();
        String xmlstring = xmlfile.tostring();
        xmlfile=null;
        DOM.Document doc=new Dom.Document();
        doc.load(xmlstring);
        DOM.XmlNode root = doc.getRootElement();
        list<DOM.XmlNode> branch =root.getchildElements();
        for(DOM.XmlNode eb:branch)
        {
            Account A = New Account();
            A.Name = eb.getAttributeValue('Name');
            A.Name = eb.getAttributeValue('Mobile');
            A.Name = eb.getAttributeValue('CompanyType');
            accounts.add(A);
            }
        insert accounts;
    }
}

The following COMPONENT used in the Visualforce------------>
==============================================
<apex:page controller="Eg1_XML_Dserfromfile" >
    <apex:form>
        <apex:inputFile value="{!xmlfile}" fileName="dummyfile">
        </apex:inputFile>
        <apex:commandButton value="Click here to import" action="{!callme}"/>
    </apex:form>
</apex:page>

 

---------------------
Please, help me out.

SwethaSwetha (Salesforce Developers) 
HI Sai,
Based on error message, it looks like xmlfile variable is null when the callme method is called.This can happen if the user does not select a file before clicking the "Click here to import" button.

You can add a null check for the xmlfile variable before using it in the callme method. See below modified code
 
public class Eg1_XML_Dserfromfile 
{
    public Blob xmlfile {set;get;}
    public void callme()
    {
        if (xmlfile == null) {
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Please select a file before clicking the button.'));
            return;
        }
        list<Account> accounts = new list<Account>();
        String xmlstring = xmlfile.tostring();
        xmlfile=null;
        DOM.Document doc=new Dom.Document();
        doc.load(xmlstring);
        DOM.XmlNode root = doc.getRootElement();
        list<DOM.XmlNode> branch =root.getchildElements();
        for(DOM.XmlNode eb:branch)
        {
            Account A = New Account();
            A.Name = eb.getAttributeValue('Name');
            A.Name = eb.getAttributeValue('Mobile');
            A.Name = eb.getAttributeValue('CompanyType');
            accounts.add(A);
            }
        insert accounts;
    }
}

If this information helps, please mark the answer as best. Thank you
Zachariahson ScaifeZachariahson Scaife
The error message you're encountering, "Argument cannot be null," usually indicates that a required value is missing when calling the method callme on the Eg1_XML_Dserfromfile class. You should review the code . (https://garagedoorrepairpetersburgva.net/dont-wait-until-its-too-late-signs-you-need-garage-door-repair/) in that class and the logic within the callme method to ensure all required arguments are being provided before the method call.
If you need further assistance, sharing the relevant code snippet could help pinpoint the issue more precisely.