function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Supriyo Ghosh 9Supriyo Ghosh 9 

SMS trigger not working

Hi,

I have written one class and onee trigeer for sendinf sms.but it is not working.Please help.

Class : 

public class SMSTask {

 public string strMobNo{ get; set; }
    
    public SMSTask(ApexPages.StandardController controller){
        String MBRid;
    }
        
    public SMSTask () { }
    
    Public void sendMessage(){
        Http http  = new Http(); 
        HttpRequest req = new HttpRequest(); 
        String fromNum='918973147939';
        //String toNum= '919790882125';
        strMobNo = '919790882125';
        req.setEndpoint('http://www.myvaluefirst.com/smpp/sendsms?username=dempeerlesshttp&password=demo4321&to=91'+strMobNo+'&from='+fromNum+'&text=hi'); 
        req.setMethod('GET');
        if (test.isRunningTest()!=true) HttpResponse res = http.send(req); 
        //XMLDom responseXML = new XMLDom(res.getBody());   
    }
    
    @future (callout=true)
    Public static void smsCustomer1(Id tskId) {
        SMS_Settings__c smsS = [select id, Name, senderId__c,task_sms__c,Mobile_Number__c, ValueFirst_Username__c, ValueFirst_Password__c from SMS_Settings__c where name ='Proposal2'] ; 
        Task tsk = [select id,Status,Proposal_Number__r.Account_Name__r.FirstName,Proposal_Number__r.Account_Name__r.LastName,Proposal_Number__r.Account_Name__r.PersonMobilePhone 
                    from Task where id=:tskId];
                                            
        String fromNo = smsS.senderId__c; //'PGFIIT';
        String toNo =  '91' + tsk.Proposal_Number__r.Account_Name__r.PersonMobilePhone; // '919790882125'; // 
        String Name = tsk.Proposal_Number__r.Account_Name__r.FirstName + ' '+ tsk.Proposal_Number__r.Account_Name__r.LastName; 
        //system.debug(Name + '\n'+ppd.Paid_Amount__c+'\n'+ppd.Premium__r.Proposal_Number__c);
        String message = smss.task_sms__c.replace('CUSTNAME', Name);
        //message = message.replace('PAYAMOUNT', String.valueOf(ppd.Paid_Amount__c));
        //message = message.replace('PROPID', ppd.Premium__r.Proposal_Number__c); 
        String xmlMessage = '<?xml version="1.0" encoding="ISO-8859-1"?>';
                xmlMessage += '<!DOCTYPE MESSAGE SYSTEM "http://127.0.0.1/psms/dtd/message.dtd" >';
                xmlMessage += '<MESSAGE><USER USERNAME="'+smss.ValueFirst_Username__c+'" PASSWORD="'+smss.ValueFirst_Password__c+'"/>';
                xmlMessage += '<SMS UDH="0" CODING="1" TEXT="'+message +'" PROPERTY="0" ID="'+tskId+'">';
                xmlMessage += '<ADDRESS FROM="'+ fromNo +'" TO="'+toNo +'" SEQ="1" TAG="Premium Payment" />';
                xmlMessage += '</SMS></MESSAGE>';
        String encodedUrl = 'http://api.myvaluefirst.com/psms/servlet/psms.Eservice2?action=send&data='+EncodingUtil.urlEncode(xmlMessage, 'UTF-8');
        String decodedUrl = EncodingUtil.urlDecode(encodedUrl, 'UTF-8');  system.debug(decodedUrl);
        Http h = new Http(); 
        HttpRequest req = new HttpRequest(); 
        req.setEndpoint(encodedUrl); 
        req.setMethod('GET');
        if (test.isRunningTest()!=true) {
            HttpResponse res = invokeWebService(h, req); handleWebServiceResponseCust(tskId);
            system.debug(res.getBody());
        } else {
            handleWebServiceResponseCust(tskId);
        }
    }
    
    public static HttpResponse invokeWebService(Http h, HttpRequest req){
        HttpResponse res = h.send(req); return res;
    }

  public static void handleWebServiceResponseCust(String tskid){
        Task tsk = [select id,Status,task_sms__c,Proposal_Number__r.Account_Name__r.PersonMobilePhone from Task where id=:tskId];
        if (tsk.Status == 'Completed') {
            tsk.task_sms__c = true;
            update tsk;
        }
    }



}



Trigger :

trigger SendSMS_Task on Task (after update) {
    
   
   if(trigger.oldmap != trigger.newmap)
   {
    map<Id, Task> mapPD = new map<Id, Task>();
    set<Id> setPId = new set<Id>();
    set<Id> setTK_cust = new set<Id>();
    
    
    
    for (Task tskRow: [select id,Status,task_sms__c,Proposal_Number__r.Account_Name__r.PersonMobilePhone from Task
                                             where Status = 'Completed']){
        system.debug(' Task ->  '+ tskRow);
        for (Task tkRow: trigger.new) {
            
                if(trigger.oldMap.get(tkRow.id).Status == 'Completed' && tskRow.task_sms__c == false) { 
                    setTK_cust.add(tskRow.id);
                }
                
        }
    }
    
    for (String cid: setTK_cust ) {  SMSTask.smsCustomer1(cid);
    }
    
    }

}

Please help