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
Veerendar AellaVeerendar Aella 

Visualforce Error Help for this Page System.XmlException: Failed to parse XML due to: expected name start and not < (position: TEXT seen ...<CloseDate>2018-12-18</<... @6:33)

Hi All,

I am getting the above error when i try to import an xml file into the org, please help.

Error:
 Visualforce Error
Help for this Page
System.XmlException: Failed to parse XML due to: expected name start and not < (position: TEXT seen ...<CloseDate>2018-12-18</<... @6:33)
Error is in expression '{!doUpload}' in component <apex:commandButton> in page importoppxml: Class.ImportOppXML.doUpload: line 124, column 1
Class.ImportOppXML.doUpload: line 124, column 1

Apex Code: 
public class ImportOppXML {
    

    public Blob myfile{get;set;}

       public ImportOppXML(){

        reports = new List<Opportunity>();

    }

     

    public List<Opportunity> reports {get;set;}

     

    public class Oppdata {

        public String Name {get; set;}

        public Decimal Amount {get; set;}

        public Date CloseDate {get; set;}
        
        public String Description {get; set;}

        public String LeadSource {get; set;}
        
        public String NextStep {get; set;}
        
        public String StageName {get; set;}
        
        public String Type {get; set;}
        
     
    }

 
    private void parseReports(DOM.XMLNode node) {

        for (Dom.XMLNode child : node.getChildElements()) {

            if (child.getName() == 'record') {

                System.debug('child'+child);

                parseReport(child);

                //  reports.add(r);

            }

            System.debug('reports'+reports);

        }

    }

     

    private void parseReport(DOM.XMLNode node ) {

        opportunity r = new opportunity();

         

        for (Dom.XMLNode child : node.getChildElements()) {

            if (child.getName() == 'Name') {

                r.Name= child.getText().trim();

            } else if (child.getName() == 'Amount') {

                r.Amount= decimal.valueof(child.gettext().trim());
                

            } else if (child.getName() == 'CloseDate') {

                r.CloseDate= Date.valueof(child.getText().trim());

            }  else if (child.getName() == 'Description') {

                r.Description= child.getText().trim();
            
            }  else if (child.getName() == 'LeadSource') {

                r.LeadSource= child.getText().trim();
                 

            }else if (child.getName() == 'NextStep') {

                r.NextStep= child.getText().trim();
                 

            }else if (child.getName() == 'StageName') {

                r.StageName= child.getText().trim();
                
            }else if (child.getName() == 'Type') {

                r.Type= child.getText().trim();
                
                
            
            }
        }

        reports.add(r);

         upsert    reports;

    }

     

    public void doUpload() {

         

        DOM.Document doc = new DOM.Document();

        doc.load(String.valueOf(myfile.toString()));   

        parseReports(doc.getRootElement());

         

         

    }

     

}

VF:

<apex:page Controller="ImportOppXML">

        <apex:form >       

            <apex:pageblock title="Import Opportunities From XML" id="PB">
   
                <!-- inputFile for uploading XML -->

                <apex:pageblocksection >

                    <apex:pageblocksectionitem >

                        <apex:outputLabel value="Please Select XML File:"/> 

                        <apex:inputFile value="{!myfile}"> </apex:inputFile>

                    </apex:pageblocksectionitem>               

                    </apex:pageblocksection>

                <!-- Table to show the XML Result -->

                <apex:pageblocksection title="Result of XML file" columns="1" rendered="{!reports.size != null}">

                    <apex:pageblocktable value="{!reports}" var="opp">

                        <apex:column value="{!opp.Name}" headerValue="Name" />
                        <apex:column value="{!opp.Amount}" headerValue="Amount" />
                        <apex:column value="{!opp.CloseDate}" headerValue="CloseDate" />
                        <apex:column value="{!opp.Description}" headerValue="Description" />
                        <apex:column value="{!opp.LeadSource}" headerValue="LeadSource" />
                        <apex:column value="{!opp.NextStep}" headerValue="NextStep" />
                        <apex:column value="{!opp.StageName}" headerValue="StageName" />
                        <apex:column value="{!opp.Type}" headerValue="Type" />
                         

                    </apex:pageblocktable>

                </apex:pageblocksection>

                <!-- Button for calling method of controller -->

                <center>

                    <apex:commandButton value="Import Opportunities" action="{!doUpload}"/>

                </center>

            </apex:pageblock>   
            
            

            
            
            

        </apex:form>   

          

    </apex:page>

XML file: 

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Opp-data >
    <record>
        <Name>zipzip</Name>
        <Amount>65023</Amount>
        <CloseDate>2018-12-18</<CloseDate>
        <StageName>Prospecting</StageName>
    </record>
    
</Opp-data>
 
Best Answer chosen by Veerendar Aella
Raj VakatiRaj Vakati
Looks like there is a validation rule that casuing the issue .. please check the validation rule 

FIELD_CUSTOM_VALIDATION_EXCEPTION, You have exceeded the daily limit of 100k: []

for me it worked with out any issue 

All Answers

Raj VakatiRaj Vakati
Your XML file is wrong .. use this XML  


below tag is not closed properly 

        <CloseDate>2018-12-18</<CloseDate>

COmplete XML

 
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Opp-data >
    <record>
        <Name>zipzip</Name>
        <Amount>65023</Amount>
        <CloseDate>2018-12-18</CloseDate>
        <StageName>Prospecting</StageName>
    </record>
    
</Opp-data>
Veerendar AellaVeerendar Aella
Hi Raj,

I have made changes accordingly, now getting below error, Please help.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Opp-data >
    <record>
        <Name>zipzip</Name>
        <Amount>65023</Amount>
        <CloseDate>02/12/2018</CloseDate>
        <StageName>Prospecting</StageName>
    </record>
    
</Opp-data>


Error:

Visualforce Error
Help for this Page
System.DmlException: Upsert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, You have exceeded the daily limit of 100k: []
Error is in expression '{!doUpload}' in component <apex:commandButton> in page importoppxml: Class.ImportOppXML.parseReport: line 112, column 1
Class.ImportOppXML.parseReports: line 48, column 1
Class.ImportOppXML.doUpload: line 126, column 1
Class.ImportOppXML.parseReport: line 112, column 1
Class.ImportOppXML.parseReports: line 48, column 1
Class.ImportOppXML.doUpload: line 126, column 1
Raj VakatiRaj Vakati
Looks like there is a validation rule that casuing the issue .. please check the validation rule 

FIELD_CUSTOM_VALIDATION_EXCEPTION, You have exceeded the daily limit of 100k: []

for me it worked with out any issue 
This was selected as the best answer
Veerendar AellaVeerendar Aella
Works fine now.
yes, u r right..! Trigger was running in the background