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

Unit test cases



I am facing problem with unit test cases.....Recently i have integrated salesforce with outer environment.

but the problem is i got the test failure message while writing unit test cases for that.

System.NullPointerException: Attempt to de-reference a null object

Class.SendSMSHttpContact.<init>: line 9, column 1 Class.TestSendSMS.testUnas1: line 15, column 1


Code is:


public class SendSMSHttpContact {

private final Contact contact;
private final String user='some name';
private final String senderID='some';
public String receipientno{get;set;}
private final String dcs='0';
public String msgtxt{get;set;}
public String msg = msgtxt.replace(' ','%20');
private final String state='0';
String endpoint = 'sample url';

public SendSMSHttpContact(ApexPages.StandardController controller) { = (Contact)controller.getRecord();

public PageReference SendSMS() {

if (contact.MobilePhone != null) {

receipientno = contact.MobilePhone;
receipientno = receipientno.replace('+','');
receipientno = receipientno.replace(' ','');
receipientno = receipientno.replace(')','');
receipientno = receipientno.replace('(','');
receipientno = receipientno.replace('-','');

//construct an HTTP request
HttpRequest req = new HttpRequest();

//send the request
Http http = new Http();
HttpResponse res = http.send(req);

//check the response
if (res.getStatusCode() == 200) {

Task smsTask = new Task (Type='SMS',
WhoID =,
Status = 'Completed',
ActivityDate =,
Description = msg.replace('%20',' '),
Subject = 'SMS Sent'
try {
insert smsTask;
} catch (System.Dmlexception e) {
System.debug('Error: Unable to insert task: ' + e);
PageReference pg = new PageReference('/'+smsTask.Id);
return pg;
} else {

//do something
else {

//do something



unit test coding is:


private class TestSendSMS{
private static testMethod void testUnas1(){

String endpoint='';
Contact con = new Contact();
con.LastName = 'test';
con.MobilePhone ='12345';
insert con;

ApexPages.StandardController controller = new ApexPages.StandardController(con);
SendSMSHttpContact test = new SendSMSHttpContact(controller);





i am in basic stage in writting unit test cases.

can you help me to write unit test case for this.


Past two days onwards i am searching for this.


can any one help me to get out of this.!!!!!