You need to sign in to do that
Don't have an account?

Code coverage for static void method
Hello,
How to cover this portion.Please help with sample code.
@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 ='Proposal'] ;
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;
String message = smss.task_sms__c.replace('CUSTNAME', Name);
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);
}
How to cover this portion.Please help with sample code.
@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 ='Proposal'] ;
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;
String message = smss.task_sms__c.replace('CUSTNAME', Name);
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);
}
Create one setup method using @Testsetup annotation and insert all the needed data in that method. Now create your method with @isTest annotation and query the data you will get the data inserted in the setup method.
If you are using this in trigger then you have to cover the code that is calling this method it will automatically cover up this method also.
Like below code
All Answers
Create one setup method using @Testsetup annotation and insert all the needed data in that method. Now create your method with @isTest annotation and query the data you will get the data inserted in the setup method.
If you are using this in trigger then you have to cover the code that is calling this method it will automatically cover up this method also.
Like below code