Write trigger
if(Trigger.isAfter)
{
If(Trigger.IsInsert)
{
CaseHandlerCls.sendSMSInsert(trigger.new);
}
If(Trigger.IsUpdate)
{
CaseHandlerCls.sendSMS(trigger.new,trigger.oldmap,trigger.newmap);
system.debug('this is first case');
}
}
======================================
Helper class:
**********************************************************************/
public class CaseHandlerCls
{
public static void sendSMSInsert(List<Case> clist)
{
system.debug(''+clist);
for(case c:clist) // for each loop to iterate over the list of the case object
{
if(c.Case_Type__c!='Child Case')
{
String mobile=c.ContactMobile;// asssigning the phone number enter by user to a string variable mobile.
system.debug(mobile); // display the value of phone.
String caseNo =c.CaseNumber; // asssigning the case number of the user to a string variable caseNo.
Boolean newCaseRecord = c.Status.equals('Open'); // assigning the value of the status to the boolean variable newCaseRecord
system.debug(newCaseRecord); // display the value of the status enter by the user while creating a new Case.
if(newCaseRecord) // condition check if the value of the status field is true than it will call the webservice class
{
webpostservice.sendSMSInsertNewMethod('Open',mobile,caseNo);
// calling the web service class with three parameters, one for status,second for the phone numbe and third for case number.
}
}
}
}
public static void sendSMS(List<Case> caselist ,map<Id,Case> oldmap,map<Id,case> newmap)
{
for (case case1 : caselist) // for each loop to iterate over the list of the case object
{
if(case1.Case_Type__c!='Child Case')
{
// Access the "old" record by its ID
case oldcase = oldmap.get(case1.Id);
Boolean oldCaseNew = oldcase.Status.equals('Open');
Boolean oldCaseNew1 = oldcase.Status.equals('On Hold');
Boolean oldCaseNew2 = oldcase.Status.equals('Escalated');
Boolean oldCaseNew3 = oldcase.Status.equals('Critical');
Boolean oldCaseNew4 = oldcase.Status.equals('Working');
Boolean oldCaseNew5 = oldcase.Status.equals('Assigned to FT');
Boolean oldCaseNew6 = oldcase.Status.equals('Assigned to SPOC');
Boolean oldCaseNew7 = oldcase.Status.equals('Satisfied and Closed');
Boolean oldCaseNew8 = oldcase.Status.equals('FTR and Closed');
// Access the new value of the status field
case newcase = newmap.get(case1.Id);
Boolean newCaseNew = newcase.Status.equals('Open');
Boolean newCaseNew1 = newcase.Status.equals('On Hold');
Boolean newCaseNew2 = newcase.Status.equals('Escalated');
Boolean newCaseNew3 = newcase.Status.equals('Critical');
Boolean newCaseNew4 = newcase.Status.equals('Working');
Boolean newCaseNew5 = newcase.Status.equals('Assigned to FT');
Boolean newCaseNew6 = newcase.Status.equals('Assigned to SPOC');
Boolean newCaseNew7 = newcase.Status.equals('Satisfied and Closed');
Boolean newCaseNew8 = newcase.Status.equals('FTR and Closed');
String mobile=newcase.ContactMobile; // access the new value of the phone and store in the variable mobile
String caseNo1 =newcase.CaseNumber;
if (oldCaseNew && newCaseNew7) // condition check for the old value as New and new Value as closed
{
webpostservice.sendSMSUpdateClosedMethod('Satisfied and Closed',mobile,caseNo1);
// call the webservice class
}
if(oldcaseNew1 && newCaseNew7) // condition check for the old value as On Hold and new Value as closed
{
webpostservice.sendSMSUpdateClosedMethod('Satisfied and Closed',mobile,caseNo1);
// call the webservice class
}
if(oldcaseNew2 && newCaseNew7) // condition check for the old value as Escalated and new Value as closed
{
webpostservice.sendSMSUpdateClosedMethod('Satisfied and Closed',mobile,caseNo1);
// call the webservice class
}
if(oldcaseNew3 && newCaseNew7) // condition check for the old value as Critical and new Value as closed
{
webpostservice.sendSMSUpdateClosedMethod('Satisfied and Closed',mobile,caseNo1);
// call the webservice class
if(oldcaseNew4 && newCaseNew7) // condition check for the old value as Working and new Value as closed
{
webpostservice.sendSMSUpdateClosedMethod('Satisfied and Closed',mobile,caseNo1);
// call the webservice class
}
if(oldcaseNew5 && newCaseNew7) // condition check for the old value as Assigned to FT and new Value as closed
{
webpostservice.sendSMSUpdateClosedMethod('Satisfied and Closed',mobile,caseNo1);
// call the webservice class
}
if(oldcaseNew6 && newCaseNew7) // condition check for the old value as Assigned to SPOC and new Value as closed
{
webpostservice.sendSMSUpdateClosedMethod('Satisfied and Closed',mobile,caseNo1);
// call the webservice class
}
if(oldCaseNew8 && newCaseNew7)
{
webpostservice.sendSMSUpdateClosedMethod('Satisfied and Closed',mobile,caseNo1);
}
if (oldCaseNew && newCaseNew8) // condition check for the old value as New and new Value as FTR and Closed
{
webpostservice.sendSMSUpdateClosedMethod1('FTR and Closed',mobile,caseNo1);
// call the webservice class
}
if(oldcaseNew1 && newCaseNew8) // condition check for the old value as On Hold and new Value as FTR and Closed
{
webpostservice.sendSMSUpdateClosedMethod1('FTR and Closed',mobile,caseNo1);
// call the webservice class
}
if(oldcaseNew2 && newCaseNew8) // condition check for the old value as Escalated and new Value as FTR and Closed
{
webpostservice.sendSMSUpdateClosedMethod1('FTR and Closed',mobile,caseNo1);
// call the webservice class
}
if(oldcaseNew3 && newCaseNew8) // condition check for the old value as Critical and new Value asFTR and Closed
{
webpostservice.sendSMSUpdateClosedMethod1('FTR and Closed',mobile,caseNo1);
// call the webservice class
}
if(oldcaseNew4 && newCaseNew8) // condition check for the old value as Working and new Value asFTR and Closed
{
webpostservice.sendSMSUpdateClosedMethod1('FTR and Closed',mobile,caseNo1);
// call the webservice class
}
if(oldcaseNew5 && newCaseNew8) // condition check for the old value as Assigned to FT and new Value as FTR and Closed
{
webpostservice.sendSMSUpdateClosedMethod1('FTR and Closed',mobile,caseNo1);
// call the webservice class
}
if(oldcaseNew6 && newCaseNew8) // condition check for the old value as Assigned to SPOC and new Value as FTR and Closed
{
webpostservice.sendSMSUpdateClosedMethod1('FTR and Closed',mobile,caseNo1);
// call the webservice class
}
if(oldcaseNew7 && newCaseNew8) // condition check for the old value as Satisfied and Closed and new Value as FTR and Closed
{
webpostservice.sendSMSUpdateClosedMethod1('FTR and Closed',mobile,caseNo1);
// call the webservice class
}
}
}
}
}
}
=====================================================
Helper WebService:
public class webpostservice
{
@future (callout=true)
public static void sendSMSInsertNewMethod(String status3 ,String Mob3,String caseNo)
{
system.debug(status3+''+Mob3+''+caseNo);
HttpRequest req3 = new HttpRequest(); // declare variable for request.
HttpResponse res3 = new HttpResponse(); // declare variable to store the response.
Http http3 = new Http(); // for authentication purpose
String message3 = 'default'; // default message stored in the variable message3.
if(status3 == 'Open')
{ // condition check, if the status of the lead is New
list<Case__mdt> l=[SELECT MasterLabel,sms__c FROM Case__mdt];
system.debug('The metadata list is:'+l);
List<Case__mdt> metalist=[select id,Check_SMS__c,sms__c,MasterLabel from Case__mdt];
for(Case__mdt cm:metalist)
{
if(cm.MasterLabel=='Create Record' && cm.Check_SMS__c==True)
{
message3=cm.sms__c+' '+caseNo;
}
system.debug(message3);
}
}
String msg3 = EncodingUtil.urlEncode(message3, 'UTF-8'); // encoding the message
req3.setEndpoint('http://www.teleshoppe.com/serv/BulkPush/?user==12378&msisdn='+Mob3+'&sender=IND&type=text&message='+msg3);
// req3.setEndpoint('http://bulkpush.mytoday.com/BulkSms/SingleMsgApi?feedid=378&username=11111&password=1111djwgt&To='+Mob3+'&Text='+msg3);
// set the end point to hit the bulk sms api with few parameters.
system.debug(msg3); // display the message.
req3.setMethod('POST'); // POST requests are used to send data to the API sever to create or udpate a resource.
req3.setTimeout(20000); // set the time out.
req3.setCompressed(true); // If true , the request body is compressed,
try
{
res3 = http3.send(req3); // sending request to the bulk sms through variable req3
System.debug('Res : '+res3.toString()); // display the response.
System.debug('Req : '+req3.toString()); // display the request.
}
catch(Exception e)
{
System.debug('Callout error: '+ e); // display the error
System.debug(req3.toString());
}
}
if(Trigger.isAfter)
{
If(Trigger.IsInsert)
{
CaseHandlerCls.sendSMSInsert(trigger.new);
}
If(Trigger.IsUpdate)
{
CaseHandlerCls.sendSMS(trigger.new,trigger.oldmap,trigger.newmap);
system.debug('this is first case');
}
}
======================================
Helper class:
**********************************************************************/
public class CaseHandlerCls
{
public static void sendSMSInsert(List<Case> clist)
{
system.debug(''+clist);
for(case c:clist) // for each loop to iterate over the list of the case object
{
if(c.Case_Type__c!='Child Case')
{
String mobile=c.ContactMobile;// asssigning the phone number enter by user to a string variable mobile.
system.debug(mobile); // display the value of phone.
String caseNo =c.CaseNumber; // asssigning the case number of the user to a string variable caseNo.
Boolean newCaseRecord = c.Status.equals('Open'); // assigning the value of the status to the boolean variable newCaseRecord
system.debug(newCaseRecord); // display the value of the status enter by the user while creating a new Case.
if(newCaseRecord) // condition check if the value of the status field is true than it will call the webservice class
{
webpostservice.sendSMSInsertNewMethod('Open',mobile,caseNo);
// calling the web service class with three parameters, one for status,second for the phone numbe and third for case number.
}
}
}
}
public static void sendSMS(List<Case> caselist ,map<Id,Case> oldmap,map<Id,case> newmap)
{
for (case case1 : caselist) // for each loop to iterate over the list of the case object
{
if(case1.Case_Type__c!='Child Case')
{
// Access the "old" record by its ID
case oldcase = oldmap.get(case1.Id);
Boolean oldCaseNew = oldcase.Status.equals('Open');
Boolean oldCaseNew1 = oldcase.Status.equals('On Hold');
Boolean oldCaseNew2 = oldcase.Status.equals('Escalated');
Boolean oldCaseNew3 = oldcase.Status.equals('Critical');
Boolean oldCaseNew4 = oldcase.Status.equals('Working');
Boolean oldCaseNew5 = oldcase.Status.equals('Assigned to FT');
Boolean oldCaseNew6 = oldcase.Status.equals('Assigned to SPOC');
Boolean oldCaseNew7 = oldcase.Status.equals('Satisfied and Closed');
Boolean oldCaseNew8 = oldcase.Status.equals('FTR and Closed');
// Access the new value of the status field
case newcase = newmap.get(case1.Id);
Boolean newCaseNew = newcase.Status.equals('Open');
Boolean newCaseNew1 = newcase.Status.equals('On Hold');
Boolean newCaseNew2 = newcase.Status.equals('Escalated');
Boolean newCaseNew3 = newcase.Status.equals('Critical');
Boolean newCaseNew4 = newcase.Status.equals('Working');
Boolean newCaseNew5 = newcase.Status.equals('Assigned to FT');
Boolean newCaseNew6 = newcase.Status.equals('Assigned to SPOC');
Boolean newCaseNew7 = newcase.Status.equals('Satisfied and Closed');
Boolean newCaseNew8 = newcase.Status.equals('FTR and Closed');
String mobile=newcase.ContactMobile; // access the new value of the phone and store in the variable mobile
String caseNo1 =newcase.CaseNumber;
if (oldCaseNew && newCaseNew7) // condition check for the old value as New and new Value as closed
{
webpostservice.sendSMSUpdateClosedMethod('Satisfied and Closed',mobile,caseNo1);
// call the webservice class
}
if(oldcaseNew1 && newCaseNew7) // condition check for the old value as On Hold and new Value as closed
{
webpostservice.sendSMSUpdateClosedMethod('Satisfied and Closed',mobile,caseNo1);
// call the webservice class
}
if(oldcaseNew2 && newCaseNew7) // condition check for the old value as Escalated and new Value as closed
{
webpostservice.sendSMSUpdateClosedMethod('Satisfied and Closed',mobile,caseNo1);
// call the webservice class
}
if(oldcaseNew3 && newCaseNew7) // condition check for the old value as Critical and new Value as closed
{
webpostservice.sendSMSUpdateClosedMethod('Satisfied and Closed',mobile,caseNo1);
// call the webservice class
if(oldcaseNew4 && newCaseNew7) // condition check for the old value as Working and new Value as closed
{
webpostservice.sendSMSUpdateClosedMethod('Satisfied and Closed',mobile,caseNo1);
// call the webservice class
}
if(oldcaseNew5 && newCaseNew7) // condition check for the old value as Assigned to FT and new Value as closed
{
webpostservice.sendSMSUpdateClosedMethod('Satisfied and Closed',mobile,caseNo1);
// call the webservice class
}
if(oldcaseNew6 && newCaseNew7) // condition check for the old value as Assigned to SPOC and new Value as closed
{
webpostservice.sendSMSUpdateClosedMethod('Satisfied and Closed',mobile,caseNo1);
// call the webservice class
}
if(oldCaseNew8 && newCaseNew7)
{
webpostservice.sendSMSUpdateClosedMethod('Satisfied and Closed',mobile,caseNo1);
}
if (oldCaseNew && newCaseNew8) // condition check for the old value as New and new Value as FTR and Closed
{
webpostservice.sendSMSUpdateClosedMethod1('FTR and Closed',mobile,caseNo1);
// call the webservice class
}
if(oldcaseNew1 && newCaseNew8) // condition check for the old value as On Hold and new Value as FTR and Closed
{
webpostservice.sendSMSUpdateClosedMethod1('FTR and Closed',mobile,caseNo1);
// call the webservice class
}
if(oldcaseNew2 && newCaseNew8) // condition check for the old value as Escalated and new Value as FTR and Closed
{
webpostservice.sendSMSUpdateClosedMethod1('FTR and Closed',mobile,caseNo1);
// call the webservice class
}
if(oldcaseNew3 && newCaseNew8) // condition check for the old value as Critical and new Value asFTR and Closed
{
webpostservice.sendSMSUpdateClosedMethod1('FTR and Closed',mobile,caseNo1);
// call the webservice class
}
if(oldcaseNew4 && newCaseNew8) // condition check for the old value as Working and new Value asFTR and Closed
{
webpostservice.sendSMSUpdateClosedMethod1('FTR and Closed',mobile,caseNo1);
// call the webservice class
}
if(oldcaseNew5 && newCaseNew8) // condition check for the old value as Assigned to FT and new Value as FTR and Closed
{
webpostservice.sendSMSUpdateClosedMethod1('FTR and Closed',mobile,caseNo1);
// call the webservice class
}
if(oldcaseNew6 && newCaseNew8) // condition check for the old value as Assigned to SPOC and new Value as FTR and Closed
{
webpostservice.sendSMSUpdateClosedMethod1('FTR and Closed',mobile,caseNo1);
// call the webservice class
}
if(oldcaseNew7 && newCaseNew8) // condition check for the old value as Satisfied and Closed and new Value as FTR and Closed
{
webpostservice.sendSMSUpdateClosedMethod1('FTR and Closed',mobile,caseNo1);
// call the webservice class
}
}
}
}
}
}
=====================================================
Helper WebService:
public class webpostservice
{
@future (callout=true)
public static void sendSMSInsertNewMethod(String status3 ,String Mob3,String caseNo)
{
system.debug(status3+''+Mob3+''+caseNo);
HttpRequest req3 = new HttpRequest(); // declare variable for request.
HttpResponse res3 = new HttpResponse(); // declare variable to store the response.
Http http3 = new Http(); // for authentication purpose
String message3 = 'default'; // default message stored in the variable message3.
if(status3 == 'Open')
{ // condition check, if the status of the lead is New
list<Case__mdt> l=[SELECT MasterLabel,sms__c FROM Case__mdt];
system.debug('The metadata list is:'+l);
List<Case__mdt> metalist=[select id,Check_SMS__c,sms__c,MasterLabel from Case__mdt];
for(Case__mdt cm:metalist)
{
if(cm.MasterLabel=='Create Record' && cm.Check_SMS__c==True)
{
message3=cm.sms__c+' '+caseNo;
}
system.debug(message3);
}
}
String msg3 = EncodingUtil.urlEncode(message3, 'UTF-8'); // encoding the message
req3.setEndpoint('http://www.teleshoppe.com/serv/BulkPush/?user==12378&msisdn='+Mob3+'&sender=IND&type=text&message='+msg3);
// req3.setEndpoint('http://bulkpush.mytoday.com/BulkSms/SingleMsgApi?feedid=378&username=11111&password=1111djwgt&To='+Mob3+'&Text='+msg3);
// set the end point to hit the bulk sms api with few parameters.
system.debug(msg3); // display the message.
req3.setMethod('POST'); // POST requests are used to send data to the API sever to create or udpate a resource.
req3.setTimeout(20000); // set the time out.
req3.setCompressed(true); // If true , the request body is compressed,
try
{
res3 = http3.send(req3); // sending request to the bulk sms through variable req3
System.debug('Res : '+res3.toString()); // display the response.
System.debug('Req : '+req3.toString()); // display the request.
}
catch(Exception e)
{
System.debug('Callout error: '+ e); // display the error
System.debug(req3.toString());
}
}
No comments:
Post a Comment