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
basha skbasha sk 

parse the xml data and insert the data in to salesfofce?

Hi All,

 I'm trying to parse the xml response and insert the data into sObject but the data doesn't inserting to salesforce .

//Actual REsponse response :

XML Response:::<?xml version="1.0" encoding="utf-8"?><results><status code="ok"/><OWASP_CSRF_TOKEN><token>2c488c4b05a987fe174d54a12b6cd8bf3705802bfafd0beb2feded0b68b8e8c8</token></OWASP_CSRF_TOKEN><common locale="en" time-zone-id="85" time-zone-java-id="UTC"><cookie>apac1breezx8x68fmfzh3dczk7</cookie><date>2018-02-06T06:18:32.003+00:00</date><host>https://meet30705009.adobeconnect.com</host><local-host>pacapac1app05</local-host><admin-host>apac1cps.adobeconnect.com</admin-host><url>/api/xml?action=common-info</url><version>9.7.0</version><tos-version>9.5</tos-version><product-notification>true</product-notification><account account-id="1309160790"/><user-agent>SFDC-Callout/41.0</user-agent><mobile-app-package>air.com.adobe.connectpro</mobile-app-package></common><reg-user><is-reg-user>false</is-reg-user></reg-user></results>

customized response :
------------------------------
XML Response:::<?xml version="1.0" encoding="utf-8"?><common locale="en" time-zone-id="85" time-zone-java-id="UTC"><cookie>apac1breezx8x68fmfzh3dczk7</cookie><date>2018-02-06T06:18:32.003+00:00</date><host>https://meet30705009.adobeconnect.com</host><local-host>pacapac1app05</local-host><admin-host>apac1cps.adobeconnect.com</admin-host><url>/api/xml?action=common-info</url><version>9.7.0</version><tos-version>9.5</tos-version><product-notification>true</product-notification><account account-id="1309160790"/><user-agent>SFDC-Callout/41.0</user-agent><mobile-app-package>air.com.adobe.connectpro</mobile-app-package></common>
        

In the below apex class if i'm passing the customized response the data inserts in to salesforce but if i'm using actual response the data doesn't inserting into salesforce please check the below apex class once 


apex class:
---------------------


global class XMLLoginAccess {
    
    public string XMLString1 {get;set;}
     private List<LightiningEd__Login_Access__c> logindetails{get;set;}
     LightiningEd__Login_Access__c adobelogin;
     List<String> id1 = new List<String>();
    public XMLLoginAccess(){
                   
        System.debug('XML Response:::'+XMLString1);
        DOM.Document doc =new DOM.Document();
        try{
            doc.load(XMLString1);
            DOM.XmlNode rootNode = doc.getRootElement();
            parseXML(rootNode);
            logindetails.add(adobelogin);
            upsert logindetails;
            System.debug('List of Events'+logindetails);   
            }catch(exception e){        
            system.debug(e.getMessage());            
        }
    }
    
      private List<LightiningEd__Login_Access__c> parseXML(DOM.XMLNode node){       
        if (node.getNodeType() == DOM.XMLNodeType.ELEMENT){        
            if(node.getName()=='common'){                                    
                    logindetails.add(adobelogin);
                    adobelogin = new LightiningEd__Login_Access__c();
            }                                
                        adobelogin.name='Test';
                                   
                    if(node.getName()=='cookie')
                       adobelogin.LightiningEd__Cookie__c = node.getText().trim();
                       System.debug('Cookie Value:::'+adobelogin.LightiningEd__Cookie__c);            
                    if(node.getName()=='host')                     
                       adobelogin.LightiningEd__Host__c  = node.getText().trim(); 
                       System.debug('Host Value:::'+adobelogin.LightiningEd__Host__c);
                    if(node.getName()=='version')     
                       adobelogin.LightiningEd__Version__c =  node.getText().trim();
                       System.debug('Version Value:::'+adobelogin.LightiningEd__Version__c);                                             
                    } 
                 for(Dom.XMLNode child: node.getChildElements()){
                parseXML(child);            
            }        
         return logindetails;
    }
    
    public List<LightiningEd__Login_Access__c> getEventsList(){
        return logindetails;
    }
}

Thanks In advance