Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public PageReference sendBulkSMSToLeads(){
- List<Lead> matchingLeadsList = [Select MobilePhone from Lead where Status =:leadStatus and Intake_Month__c =:intakeMonth
- and Intake_Year__c =:intakeYear];
- Set<String> uniquePhoneNumberList = new Set<String>();
- if(matchingLeadsList != null && matchingLeadsList.size() > 0){
- String commaSeparatedMobileNumbers = '';
- for(Lead lead : matchingLeadsList){
- if(lead.MobilePhone != null && lead.MobilePhone != ''){
- if(!uniquePhoneNumberList.contains(lead.MobilePhone)){
- uniquePhoneNumberList.add(lead.MobilePhone);
- commaSeparatedMobileNumbers = commaSeparatedMobileNumbers + ',' + lead.MobilePhone;
- }
- }
- }
- if(commaSeparatedMobileNumbers.length() > 0){
- commaSeparatedMobileNumbers = commaSeparatedMobileNumbers.substring(1, commaSeparatedMobileNumbers.length());
- }
- String payLoad = 'username=global&password=muzztech&mobile=' +commaSeparatedMobileNumbers + '&sendername=SPJAIN&message='+message;
- Http h = new Http();
- HttpRequest req = new HttpRequest();
- req.setEndpoint('http://priority.muzztech.in/sms_api/sendsms.php');
- req.setMethod('POST');
- req.setBody(payLoad);
- HttpResponse res = h.send(req);
- ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.INFO,'Bulk SMS initiated for ' + matchingLeadsList.size() + ' leads');
- ApexPages.addMessage(myMsg);
- }else{
- ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'No matching leads found to send SMS');
- ApexPages.addMessage(myMsg);
- }
- return null;
- }
- static testMethod void sendBulkSMSToLeadsTest() {
- Test.startTest();
- SMSController ctrl = new SMSController();
- ctrl.leadStatus = 'Hot';
- ctrl.intakeMonth = 'January';
- ctrl.intakeYear = '2017';
- Lead leadObj = new Lead(LastName='Test', Email='unittest2@gmail.com', MobilePhone='7854945777', Status = 'Hot', LeadSource = 'Chat', Intake_Year__c = '2017', Intake_Month__c = 'January');
- insert leadObj;
- ctrl.sendBulkSMSToLeads();
- Test.stopTest();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement