Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Hi Everyone,
- I'm Integrating Salesforce wiith Adobe connect and inserting the users list into salesforce for that i have developed a REST API.
- I got the reponse in XML format and i wrote the xml class for parsing the response.
- I go the response like below "actual response"
- How to change the Actual response like Filtered response.because filtered response works perfectly.
- Actual Response ::: <?xml version="1.0" encoding="utf-8"?><results><status code="ok"/><poll_questions/><registration_questions><question id="1308421076" description="Campaign Tracking ID"/></registration_questions><user_list><user principal_id="1300650026" permission_id="View" name="chanbasha sk" login="skbasha467@gmail.com" registration_time=" " attendance_status="Attended" first_in_time=" " duration="01:23:44" isLead="No" registration_question_1308421076=" " campaign_alias_1308421076=" " idp-source=" "/><user principal_id="1302642885" permission_id="Invited" name="test Sk" login="cnoorbashasheik@miraclesoft.com" registration_time=" " attendance_status="Not Attended" first_in_time=" " duration="00:00:00" isLead="No" registration_question_1308421076=" " campaign_alias_1308421076=" " idp-source=" "/></user_list></results>
- -----------------
- Filtered Response ::: <?xml version="1.0" encoding="utf-8"?><user_list><user principal_id="1300650026" permission_id="View" name="chanbasha sk" login="skbasha467@gmail.com" registration_time=" " attendance_status="Attended" first_in_time=" " duration="01:23:44" isLead="No" registration_question_1308421076=" " campaign_alias_1308421076=" " idp-source=" "/><user principal_id="1302642885" permission_id="Invited" name="test Sk" login="cnoorbashasheik@miraclesoft.com" registration_time=" " attendance_status="Not Attended" first_in_time=" " duration="00:00:00" isLead="No" registration_question_1308421076=" " campaign_alias_1308421076=" " idp-source=" "/></user_list>
- --------------------
- Here I'm directly passing the actual response for inserting the data i got error like "common.apex.api.dom.XmlNode$Attribute@68655084],null,null,null,]"
- if i'm using the actual response I got the null values inthis line :
- System.debug(userNode.getAttributeValue('principal_id', null) + ' : ' + userNode.getAttributeValue('name', null) + ' : ' + userNode.getAttributeValue('attendance_status', null));
- if i'm using the filtered response it works perfectly.
- here if i'm passing the above customized response the data successfully inserting into salesforce.
- This is my Class :
- -------------------
- global class XMLparserUpdate{
- public String XMLString1 {get;set;}
- public String EvenId;
- private list<LightiningEd__Webinar_Attendees_Status__c> lstevents{get;set;}
- LightiningEd__Webinar_Attendees_Status__c adobeevent;
- global XMLparserUpdate(String XMLString,String eventid,String Name){
- //String XMLString,String eventid,String Name
- lstevents = new list<LightiningEd__Webinar_Attendees_Status__c>();
- EvenId = EventId;
- System.debug(' '+EvenId);
- XMLString1 = XMLString;
- actual response : // XMLString ='<?xml version="1.0" encoding="utf-8"?><results><status code="ok"/><poll_questions/><registration_questions><question id="1308421076" description="Campaign Tracking ID"/></registration_questions><user_list><user principal_id="1300650026" permission_id="View" name="chanbasha sk" login="skbasha467@gmail.com" registration_time=" " attendance_status="Attended" first_in_time=" " duration="01:23:44" isLead="No" registration_question_1308421076=" " campaign_alias_1308421076=" " idp-source=" "/><user principal_id="1302642885" permission_id="Invited" name="test Sk" login="cnoorbashasheik@miraclesoft.com" registration_time=" " attendance_status="Not Attended" first_in_time=" " duration="00:00:00" isLead="No" registration_question_1308421076=" " campaign_alias_1308421076=" " idp-source=" "/></user_list></results>';
- Filtered response : // XMLString ='<?xml version="1.0" encoding="utf-8"?><user_list><user principal_id="1300650026" permission_id="View" name="chanbasha sk" login="skbasha467@gmail.com" registration_time=" " attendance_status="Attended" first_in_time=" " duration="01:23:44" isLead="No" registration_question_1308421076=" " campaign_alias_1308421076=" " idp-source=" "/><user principal_id="1302642885" permission_id="Invited" name="test Sk" login="cnoorbashasheik@miraclesoft.com" registration_time=" " attendance_status="Not Attended" first_in_time=" " duration="00:00:00" isLead="No" registration_question_1308421076=" " campaign_alias_1308421076=" " idp-source=" "/></user_list>';
- DOM.Document doc=new DOM.Document();
- try{
- doc.load(XMLString);
- DOM.XmlNode userList=doc.getRootElement();
- for(Dom.XmlNode userNode : userList.getChildElements()){
- System.debug(userNode.getAttributeValue('principal_id', null) + ' : ' + userNode.getAttributeValue('name', null) + ' : ' + userNode.getAttributeValue('attendance_status', null));
- adobeevent = new LightiningEd__Webinar_Attendees_Status__c();
- adobeevent.name = userNode.getAttributeValue('name', null);
- adobeevent.LightiningEd__Login__c = userNode.getAttributeValue('login', null);
- adobeevent.LightiningEd__Attandance_Status__c = userNode.getAttributeValue('attendance_status', null);
- adobeevent.LightiningEd__principal_id__c = userNode.getAttributeValue('principal_id',null);
- adobeevent.LightiningEd__Webinar__c = Name;
- lstevents.add(adobeevent);
- System.debug('lstevents:::'+lstevents);
- }
- }catch(Exception e){
- System.debug(e.getMessage());
- }
- if(lstevents.size()>0){
- upsert lstevents LightiningEd__principal_id__c ; //To removing the duplicates
- }
- }
- }
- REST CLASS :
- -----------
- global class SelectedWebinarListUpdate {
- @future(callout=true)
- global static void updateWebinar(String username,String password,String url,String eventid,String Name){
- Http http = new Http();
- HttpRequest req = new HttpRequest();
- HttpResponse res = new HttpResponse();
- Blob headerValue = Blob.valueOf(username + ':' + password);
- String authorizationHeader = 'BASIC ' +
- EncodingUtil.base64Encode(headerValue);
- req.setHeader('Authorization', authorizationHeader);
- req.setEndpoint(url+'/api/xml?action=report-event-participants-complete-information&account-id=1300650024&session=apac1breezcazys9urevbqsnio&sco-id='+eventid);
- req.setMethod('GET');
- req.setHeader('Content-Type', 'application/json');
- req.setHeader('Accept','application/json');
- try {
- res = http.send(req);
- System.debug('MyResult == :'+res.getBody());
- XMLparserUpdate s = new XMLparserUpdate(res.getBody(),eventid,Name);
- System.debug('Response value'+s);
- }catch(System.CalloutException e){
- System.debug('Callout error: '+ e);
- }
- }
- }
- How to change the actual response like filtered response.
- Please anybody having idea help
- Thanks,
Add Comment
Please, Sign In to add comment