-1

I'm doing the adobe connect integration with salesforce.Here for getting the events list i wrote the REST API

from that i'm getting the all events but for everytime it inserts the all events and includes duplicates.

for avoiding the duplicate insertions i have created a "EXTERNALID" as unique but at the time of reading the events

i'm able to read the id value.

This is my apex REST API response

     <event sco-id="1304132220" type="event" icon="event" permission-id="view">
             <name>Salesforce Enhancements</name>
             <domain-name>meet95927113.adobeconnect.com</domain-name>
             <url-path>/salesforceenhancements/</url-path>
             <date-begin>2017-12-21T01:30:00.000+14:00</date-begin>
             <date-end>2017-12-22T02:30:00.000+14:00</date-end>
             <expired>true</expired>
             <duration>1d 01:00:00.000</duration>
          </event>

here i'm able to read the all fields like name,domain-name,....etc. but HOW TO READ SCO-ID VALUE.

This is my rest class:

        global class XMLparserCopy{

        public string XMLString1 {get;set;}
        public String scoId;
        private list<Webinar__c> lstevents{get;set;}
        LightiningEd__Webinar__c adobeevent;         
        public XMLparserCopy(String XMLString){
            lstevents = new list<Webinar__c>();
            XMLString1 = XMLString;
            //XMLString = '<?xml version="1.0" encoding="utf-8"?><my-events><event sco-id="1290617895" type="event" icon="event" permission-id="host"><name>Adobe connect demo</name><domain-name>meet64541292.adobeconnect.com</domain-name><url-path>/demo/</url-path><date-begin>2017-11-02T19:30:00.000+05:30</date-begin><date-end>2017-11-03T18:45:00.000+05:30</date-end><expired>true</expired><duration>23:15:00.000</duration></event><event sco-id="1290640959" type="event" icon="event" permission-id="view"><name>salesforce demo</name><domain-name>meet64541292.adobeconnect.com</domain-name><url-path>/dmeosfsf/</url-path><date-begin>2017-11-02T19:30:00.000+05:30</date-begin><date-end>2017-11-02T19:45:00.000+05:30</date-end><expired>true</expired><duration>00:15:00.000</duration></event><event sco-id="1290643314" type="event" icon="event" permission-id="view"><name>Test</name><domain-name>meet64541292.adobeconnect.com</domain-name><url-path>/testadobe/</url-path><date-begin>2017-11-02T18:45:00.000+05:30</date-begin><date-end>2017-11-02T20:00:00.000+05:30</date-end><expired>true</expired><duration>01:15:00.000</duration></event><event sco-id="1292076280" type="event" icon="event" permission-id="view"><name>test1</name><domain-name>meet64541292.adobeconnect.com</domain-name><url-path>/test1/</url-path><date-begin>2017-11-08T18:00:00.000+05:30</date-begin><date-end>2017-11-08T19:00:00.000+05:30</date-end><expired>true</expired><duration>01:00:00.000</duration></event><event sco-id="1292084866" type="event" icon="event" permission-id="host"><name>TestEvent</name><domain-name>meet64541292.adobeconnect.com</domain-name><url-path>/testevent/</url-path><date-begin>2017-11-08T17:45:00.000+05:30</date-begin><date-end>2017-11-09T18:45:00.000+05:30</date-end><expired>true</expired><duration>1d 01:00:00.000</duration></event><event sco-id="1292411456" type="event" icon="event" permission-id="view"><name>Salesforce Demo1</name><domain-name>meet64541292.adobeconnect.com</domain-name><url-path>/salesforcedemo1/</url-path><date-begin>2017-11-09T20:15:00.000+05:30</date-begin><date-end>2017-11-10T21:15:00.000+05:30</date-end><expired>true</expired><duration>1d 01:00:00.000</duration></event><event sco-id="1300207930" type="event" icon="event" permission-id="view"><name>Dreamforce Event</name><domain-name>meet64541292.adobeconnect.com</domain-name><url-path>/dreamforceevent/</url-path><date-begin>2017-12-05T18:00:00.000+05:30</date-begin><date-end>2017-12-05T19:00:00.000+05:30</date-end><expired>false</expired><duration>01:00:00.000</duration></event></my-events>';
            DOM.Document doc=new DOM.Document();
            try{
                doc.load(XMLString);
                DOM.XmlNode rootNode=doc.getRootElement();                
                    parseXML(rootNode);
                    lstevents.add(adobeevent);
                    insert lstevents;
                    System.debug('List of Events'+lstevents);                                  
            }catch(exception e){        
                system.debug(e.getMessage());            
            }
        }    
        private List<Webinar__c> parseXML(DOM.XMLNode node){

            if (node.getNodeType() == DOM.XMLNodeType.ELEMENT){

                if(node.getName()=='event'){

                    if(adobeevent!=null)              
                        lstevents.add(adobeevent);  
                        adobeevent = new Webinar__c();

            }      

                if(node.getName()=='name')                 
                    adobeevent.name=node.getText().trim();

                if(node.getName()=='domain-name')
                   adobeevent.LightiningEd__Registration_URL__c= node.getText().trim();            
                if(node.getName()=='date-begin')                     
                   adobeevent.LightiningEd__Start_Time__c = date.valueOf(node.getText().trim());                          
                if(node.getName()=='date-end')     
                   adobeevent.LightiningEd__Finish_Time__c =  date.valueOf(node.getText().trim());            
                if(node.getName()=='expired')
                    adobeevent.LightiningEd__Expired__c=node.getText().trim();             
                }

                for(Dom.XMLNode child: node.getChildElements()){
                    parseXML(child);            
                }        
             return lstevents;
        }   
        public List<Webinar__c> getEventsList(){
            return lstevents;
        }
    }

could anybody having idea please help me how to read SCO-ID value?

1

The apex class XmlNode has a String getAttribute(String key, String keyNamespace) method.

If you call this method on your event node, you can get the SCO-ID value. Like this:

if(node.getName()=='event'){
    String scoIdValue = node.getAttribute('sco-id', null);
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy