Guest User

Untitled

a guest
Oct 23rd, 2018
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.74 KB | None | 0 0
  1. global Class EtoCaseservices implements Messaging.InboundEmailHandler {
  2.  
  3. // Instantiate variables that we will need for handling this email
  4.  
  5. String location;
  6. String need;
  7. String service;
  8. String phone;
  9. String warranty;
  10. String po;
  11. String description;
  12. String initiator;
  13. String order;
  14. Integer locationIdx;
  15. Integer needIdx;
  16. Integer serviceIdx;
  17. Integer phoneIdx;
  18. Integer warrantyIdx;
  19. Integer poIdx;
  20. Integer descriptionIdx;
  21. Integer initiatorIdx;
  22. Integer orderIdx;
  23. String locationFinal;
  24. String needFinal;
  25. String serviceFinal;
  26. String tradeFinal;
  27. String InboxFinal;
  28. String InitiatorFinal;
  29. String TimeFinal;
  30. String poFinal;
  31. String phoneFinal;
  32. String servicenofinal;
  33. String warrantyFinal;
  34. String descriptionFinal;
  35. String orderFinal;
  36.  
  37.  
  38. global Messaging.InboundEmailResult handleInboundEmail
  39. (Messaging.InboundEmail email, Messaging.InboundEnvelope envelope){
  40. Messaging.InboundEmailResult result = new Messaging.InboundEmailResult();
  41. if (email.fromaddress =='customerone@testl.com')
  42. {
  43.  
  44.  
  45. location = 'Client: ';
  46. need = 'Need: ';
  47. service = 'Service Request #: ';
  48. phone = 'Client Contact Phone: ';
  49.  
  50. locationIdx = email.plainTextBody.indexOf(location);
  51. needIdx = email.plainTextBody.indexOf(need);
  52. serviceIdx = email.plainTextBody.indexOf(service);
  53. phoneIdx = email.plainTextBody.indexOf(phone);
  54. String[] bodySplitted = email.PlainTextBody.split('n');
  55. String descriptionFinal = email.plainTextBody.substringBetween('-----------------------------------------------------------------------------------' , '---------------------------------------------------------------------------------------------' ).normalizeSpace();
  56. locationFinal = email.plainTextBody.substring(
  57. locationIdx + location.length(), email.plainTextBody.indexOf('n', locationIdx + location.length()));
  58. String[] locNme = locationFinal.split(' ', 3);
  59.  
  60. needFinal = email.plainTextBody.substring(
  61. needIdx + need.length(), email.plainTextBody.indexOf('n', needIdx + need.length()));
  62. serviceFinal = email.plainTextBody.substring(
  63. serviceIdx + service.length(), email.plainTextBody.indexOf('n', serviceIdx + serrvice.length()));
  64. phoneFinal = email.plainTextBody.substring(
  65. phoneIdx + phone.length(), email.plainTextBody.indexOf('n',phoneIdx + phone.length()));
  66.  
  67. tradeFinal = email.plainTextBody.substringBetween('Not to Exceed: ', 'Service Level: ');
  68. InboxFinal = email.plainTextBody.substringBetween('Email Delivery Time: ', 'Client: ');
  69. InitiatorFinal = email.plainTextBody.substringBetween('RFS Initiator Name: ' , 'Client Contact Phone: ');
  70. TimeFinal = email.plainTextBody.substringBetween('Service Requested: ' , 'Email Delivery Time: ');
  71. poFinal = email.plainTextBody.substringBetween('Service Request #: ' , 'RFS State: ');
  72. servicenoFinal = email.plainTextBody.substringBetween('Service Request #: ' , '(Include this # on Invoice)');
  73. system.debug('locationFinal: ' +locationFinal);
  74. if (locationFinal != NULL) {
  75. SVMXC__Site__c [] locArray = [Select Id, Name, SVMXC__Account__r.Id from SVMXC__Site__c where Name = :locationFinal];
  76.  
  77.  
  78. try{
  79.  
  80. case c= new case();
  81. c.subject= 'BUNNSERVE REQUEST';
  82. c.Case_Type__c= 'Service Request';
  83. c.Priority='High';
  84. c.Origin='Email';
  85. c.Status='new';
  86. c.AccountId = locArray[0].SVMXC__Account__r.Id;
  87. c.SVMXC__Site__c = locArray[0].Id;
  88. c.recordtypeId = '012E0000000oRWX';
  89. c.Description= descriptionFinal + 'n' + 'Not to Exceed: ' + tradeFinal + 'n' + 'Service Requested: ' + TimeFinal;
  90. c.KA_PO__c= poFinal;
  91. c.Location_Contact_Name__c = InitiatorFinal;
  92. c.BSP_Location_Contact_Phone__c = phoneFinal;
  93. upsert c;
  94. }
  95. catch(System.dmlException e)
  96. {System.debug('Error: Unable to create new Case: ' + e);
  97. }
  98.  
  99. }
  100. else if (locationFinal == null){
  101. System.debug('No Location was found');
  102. }
  103.  
  104. }
  105.  
  106. else if (email.fromaddress =='customertwo@sample.com')
  107.  
  108. {
  109.  
  110. location = 'Site: ';
  111. Warranty = 'Warranty: ';
  112. phone = 'Caller Phone: ';
  113. po = 'The referenced work order number is ';
  114. description = 'Problem Description: ';
  115. initiator = 'Caller name: ';
  116. phone = 'Caller phone: ';
  117. locationIdx = email.plainTextBody.indexOf(location);
  118. WarrantyIdx = email.plainTextBody.indexOf(Warranty);
  119. phoneIdx = email.plainTextBody.indexOf(phone);
  120. poIdx = email.plainTextBody.indexOf(po);
  121. descriptionIdx = email.plainTextBody.indexOf(description);
  122. initiatorIdx = email.plainTextBody.indexOf(initiator);
  123. phoneIdx = email.plainTextBody.indexOf(phone);
  124.  
  125. String[] bodySplitted = email.PlainTextBody.split('n');
  126. locationFinal = email.plainTextBody.substring(
  127. locationIdx + location.length(), email.plainTextBody.indexOf('n', locationIdx + location.length()));
  128. String[] locNme = locationFinal.split(' ', 3);
  129.  
  130. WarrantyFinal = email.plainTextBody.substring(
  131. WarrantyIdx + Warranty.length(), email.plainTextBody.indexOf('n', WarrantyIdx + Warranty.length()));
  132. poFinal = email.plainTextBody.substring(
  133. poIdx + po.length(), email.plainTextBody.indexOf('n',poIdx + po.length()));
  134. descriptionFinal = email.plainTextBody.substring(
  135. descriptionIdx + description.length(), email.plainTextBody.indexOf('n', descriptionIdx + description.length()));
  136. initiatorFinal = email.plainTextBody.substring(
  137. initiatorIdx + initiator.length(), email.plainTextBody.indexOf('n', initiatorIdx + initiator.length()));
  138. phoneFinal = email.plainTextBody.substring(
  139. phoneIdx + phone.length(), email.plainTextBody.indexOf('n',phoneIdx + phone.length()));
  140.  
  141. orderFinal = email.plainTextBody.substringBetween('Date Entered: ', 'Region: ');
  142. system.debug('locationFinal: ' +locationFinal);
  143. if (locationFinal != NULL) {
  144. SVMXC__Site__c [] locArray = [Select Id, Name, SVMXC__Account__r.Id from SVMXC__Site__c where Name = :locationFinal];
  145.  
  146.  
  147. try{
  148.  
  149. case c= new case();
  150. c.subject= 'BUNNSERVE REQUEST';
  151. c.Case_Type__c= 'Service Request';
  152. c.Priority='High';
  153. c.Origin='Email';
  154. c.Status='new';
  155. c.AccountId = locArray[0].SVMXC__Account__r.Id;
  156. c.SVMXC__Site__c = locArray[0].Id;
  157. c.recordtypeId = '012E0000000oRWX';
  158. c.Description= descriptionFinal + 'n' +'n' + 'Warranty: ' + WarrantyFinal + 'n' + 'n' + 'Date Entered: ' + orderFinal;
  159. c.KA_PO__c= poFinal;
  160. c.Location_Contact_Name__c = InitiatorFinal;
  161. c.BSP_Location_Contact_Phone__c = phoneFinal;
  162. upsert c;
  163. }
  164. catch(System.dmlException e)
  165. {System.debug('Error: Unable to create new Case: ' + e);
  166. }
  167.  
  168. }
  169. else if (locationFinal == null){
  170. System.debug('No Location was found');
  171. }
  172.  
  173. }
  174. return result;
  175.  
  176. } // Close handleInboundEmail ()
  177. }
Add Comment
Please, Sign In to add comment