Guest User

Untitled

a guest
Jan 8th, 2018
351
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.44 KB | None | 0 0
  1. Hi Everyone,
  2.  
  3. I'm Integrating Salesforce wiith Adobe connect and inserting the users list into salesforce for that i have developed a REST API.
  4. I got the reponse in XML format and i wrote the xml class for parsing the response.
  5.  
  6. I go the response like below "actual response"
  7.  
  8. How to change the Actual response like Filtered response.because filtered response works perfectly.
  9.  
  10. 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>
  11. -----------------
  12. 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>
  13. --------------------
  14. 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,]"
  15.  
  16. if i'm using the actual response I got the null values inthis line :
  17.  
  18. System.debug(userNode.getAttributeValue('principal_id', null) + ' : ' + userNode.getAttributeValue('name', null) + ' : ' + userNode.getAttributeValue('attendance_status', null));
  19.  
  20. if i'm using the filtered response it works perfectly.
  21.  
  22. here if i'm passing the above customized response the data successfully inserting into salesforce.
  23.  
  24. This is my Class :
  25. -------------------
  26.  
  27. global class XMLparserUpdate{
  28.  
  29. public String XMLString1 {get;set;}
  30. public String EvenId;
  31. private list<LightiningEd__Webinar_Attendees_Status__c> lstevents{get;set;}
  32. LightiningEd__Webinar_Attendees_Status__c adobeevent;
  33.  
  34. global XMLparserUpdate(String XMLString,String eventid,String Name){
  35. //String XMLString,String eventid,String Name
  36. lstevents = new list<LightiningEd__Webinar_Attendees_Status__c>();
  37. EvenId = EventId;
  38. System.debug(' '+EvenId);
  39. XMLString1 = XMLString;
  40. 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>';
  41. 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>';
  42. DOM.Document doc=new DOM.Document();
  43. try{
  44. doc.load(XMLString);
  45. DOM.XmlNode userList=doc.getRootElement();
  46. for(Dom.XmlNode userNode : userList.getChildElements()){
  47.  
  48. System.debug(userNode.getAttributeValue('principal_id', null) + ' : ' + userNode.getAttributeValue('name', null) + ' : ' + userNode.getAttributeValue('attendance_status', null));
  49.  
  50. adobeevent = new LightiningEd__Webinar_Attendees_Status__c();
  51.  
  52. adobeevent.name = userNode.getAttributeValue('name', null);
  53. adobeevent.LightiningEd__Login__c = userNode.getAttributeValue('login', null);
  54. adobeevent.LightiningEd__Attandance_Status__c = userNode.getAttributeValue('attendance_status', null);
  55. adobeevent.LightiningEd__principal_id__c = userNode.getAttributeValue('principal_id',null);
  56. adobeevent.LightiningEd__Webinar__c = Name;
  57. lstevents.add(adobeevent);
  58. System.debug('lstevents:::'+lstevents);
  59.  
  60. }
  61. }catch(Exception e){
  62.  
  63. System.debug(e.getMessage());
  64. }
  65. if(lstevents.size()>0){
  66. upsert lstevents LightiningEd__principal_id__c ; //To removing the duplicates
  67. }
  68. }
  69. }
  70.  
  71. REST CLASS :
  72. -----------
  73.  
  74. global class SelectedWebinarListUpdate {
  75.  
  76. @future(callout=true)
  77. global static void updateWebinar(String username,String password,String url,String eventid,String Name){
  78. Http http = new Http();
  79. HttpRequest req = new HttpRequest();
  80. HttpResponse res = new HttpResponse();
  81. Blob headerValue = Blob.valueOf(username + ':' + password);
  82. String authorizationHeader = 'BASIC ' +
  83. EncodingUtil.base64Encode(headerValue);
  84. req.setHeader('Authorization', authorizationHeader);
  85. req.setEndpoint(url+'/api/xml?action=report-event-participants-complete-information&account-id=1300650024&session=apac1breezcazys9urevbqsnio&sco-id='+eventid);
  86. req.setMethod('GET');
  87. req.setHeader('Content-Type', 'application/json');
  88. req.setHeader('Accept','application/json');
  89. try {
  90. res = http.send(req);
  91. System.debug('MyResult == :'+res.getBody());
  92. XMLparserUpdate s = new XMLparserUpdate(res.getBody(),eventid,Name);
  93. System.debug('Response value'+s);
  94.  
  95. }catch(System.CalloutException e){
  96. System.debug('Callout error: '+ e);
  97.  
  98. }
  99.  
  100. }
  101.  
  102. }
  103.  
  104. How to change the actual response like filtered response.
  105.  
  106. Please anybody having idea help
  107.  
  108. Thanks,
Add Comment
Please, Sign In to add comment