Advertisement
Guest User

Untitled

a guest
Jan 3rd, 2017
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. public PageReference sendBulkSMSToLeads(){
  2. List<Lead> matchingLeadsList = [Select MobilePhone from Lead where Status =:leadStatus and Intake_Month__c =:intakeMonth
  3. and Intake_Year__c =:intakeYear];
  4. Set<String> uniquePhoneNumberList = new Set<String>();
  5. if(matchingLeadsList != null && matchingLeadsList.size() > 0){
  6. String commaSeparatedMobileNumbers = '';
  7. for(Lead lead : matchingLeadsList){
  8.  
  9. if(lead.MobilePhone != null && lead.MobilePhone != ''){
  10. if(!uniquePhoneNumberList.contains(lead.MobilePhone)){
  11. uniquePhoneNumberList.add(lead.MobilePhone);
  12. commaSeparatedMobileNumbers = commaSeparatedMobileNumbers + ',' + lead.MobilePhone;
  13. }
  14. }
  15. }
  16.  
  17. if(commaSeparatedMobileNumbers.length() > 0){
  18. commaSeparatedMobileNumbers = commaSeparatedMobileNumbers.substring(1, commaSeparatedMobileNumbers.length());
  19. }
  20.  
  21. String payLoad = 'username=global&password=muzztech&mobile=' +commaSeparatedMobileNumbers + '&sendername=SPJAIN&message='+message;
  22. Http h = new Http();
  23. HttpRequest req = new HttpRequest();
  24. req.setEndpoint('http://priority.muzztech.in/sms_api/sendsms.php');
  25. req.setMethod('POST');
  26. req.setBody(payLoad);
  27. HttpResponse res = h.send(req);
  28.  
  29. ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.INFO,'Bulk SMS initiated for ' + matchingLeadsList.size() + ' leads');
  30. ApexPages.addMessage(myMsg);
  31.  
  32. }else{
  33. ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'No matching leads found to send SMS');
  34. ApexPages.addMessage(myMsg);
  35. }
  36. return null;
  37. }
  38.  
  39. static testMethod void sendBulkSMSToLeadsTest() {
  40. Test.startTest();
  41. SMSController ctrl = new SMSController();
  42. ctrl.leadStatus = 'Hot';
  43. ctrl.intakeMonth = 'January';
  44. ctrl.intakeYear = '2017';
  45. Lead leadObj = new Lead(LastName='Test', Email='unittest2@gmail.com', MobilePhone='7854945777', Status = 'Hot', LeadSource = 'Chat', Intake_Year__c = '2017', Intake_Month__c = 'January');
  46. insert leadObj;
  47. ctrl.sendBulkSMSToLeads();
  48.  
  49. Test.stopTest();
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement