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
raju p 4raju p 4 

System.CalloutException: Endpoint can not be null

 i am getting this error >>

System.CalloutException: Endpoint can not be null
Error is in expression '{!sendsmsTwilio}' in component <apex:commandButton> in page sendsmstwilio: Class.sendsmsTwilio.sendsmsTwilio: line 28, column 1
Class.sendsmsTwilio.sendsmsTwilio: line 28, column 1

and its apex code is>>
public class sendsmsTwilio {
public string Messages{set;get;}
public string ACCOUNTSID{set;get;}  
public string AUTHTOKEN{set;get;}
  public string Mobile{set;get;}
public string result{set;get;}
public contact con;

public sendsmsTwilio(ApexPages.StandardController controller) {
con =(contact)controller.getrecord();
}
public void sendsmsTwilio(){
BoxIntrgration__c c= [SELECT  accountsid__c, AUTHTOKEN__c from BoxIntrgration__c where name=:'twilio'];
ACCOUNTSID=c.accountSid__c;
AUTHTOKEN=c.AUTHTOKEN__c;

Http p= new http();
HttpRequest req= new HttpRequest();
 string url='https://api.twilio.com/2010-04-01/Accounts/AC58cf47802fa54fe399e85fd822bf2103/Messages.json';
   string body ='Well come';
          body=body+'&To=+con.phone';
           body=body+'&AUTHTOKEN';
            body=body+'&MessagingServiceSid=MG3d0796691bb5c2d7ed266c1850240962';               

req.setmethod('POST');
httpresponse res= new httpResponse();
res=p.send(req);
result=res.getbody();


}
       
}
public class sendsmsTwilio {
public string Messages{set;get;}
public string ACCOUNTSID{set;get;}  
public string AUTHTOKEN{set;get;}
  public string Mobile{set;get;}
public string result{set;get;}
public contact con;

public sendsmsTwilio(ApexPages.StandardController controller) {
con =(contact)controller.getrecord();
}
public void sendsmsTwilio(){
BoxIntrgration__c c= [SELECT  accountsid__c, AUTHTOKEN__c from BoxIntrgration__c where name=:'twilio'];
ACCOUNTSID=c.accountSid__c;
AUTHTOKEN=c.AUTHTOKEN__c;

Http p= new http();
HttpRequest req= new HttpRequest();
 string url='https://api.twilio.com/2010-04-01/Accounts/AC58cf47802fa54fe399e85fd822bf2103/Messages.json';
   string body ='Well come';
          body=body+'&To=+con.phone';
           body=body+'&AUTHTOKEN';
            body=body+'&MessagingServiceSid=MG3d0796691bb5c2d7ed266c1850240962';               

req.setmethod('POST');
httpresponse res= new httpResponse();
res=p.send(req);
result=res.getbody();


}
       
}

 here is  i am trying to send sms from contact  and its visualforce page

<apex:page standardController="contact" extensions="sendsmsTwilio">
<apex:form >
<apex:pageblock >
<apex:inputtext value="{!contact.phone}"/>

<apeX:pageblockButtons >
<apex:commandButton value="SendSms" action="{!sendsmsTwilio}"/>
</apeX:pageblockButtons>
</apex:pageblock>
</apex:form>
{!result}
  
</apex:page>

 i  tryed using try and catch but , but i am not geting message ,please do the needful

 
Amit Chaudhary 8Amit Chaudhary 8
Please add setEndpoint method to add URL and use setBody method to add Body in request
public class sendsmsTwilio {
public string Messages{set;get;}
public string ACCOUNTSID{set;get;}  
public string AUTHTOKEN{set;get;}
public string Mobile{set;get;}
public string result{set;get;}
public contact con;

	public sendsmsTwilio(ApexPages.StandardController controller) {
		con =(contact)controller.getrecord();
	}
	
	public void sendsmsTwilio()
	{
	
		BoxIntrgration__c c= [SELECT  accountsid__c, AUTHTOKEN__c from BoxIntrgration__c where name=:'twilio'];
		ACCOUNTSID=c.accountSid__c;
		AUTHTOKEN=c.AUTHTOKEN__c;

		Http p= new http();
		HttpRequest req= new HttpRequest();
		string url='https://api.twilio.com/2010-04-01/Accounts/AC58cf47802fa54fe399e85fd822bf2103/Messages.json';
		string body ='Well come';
				  body=body+'&To=+con.phone';
				   body=body+'&AUTHTOKEN';
					body=body+'&MessagingServiceSid=MG3d0796691bb5c2d7ed266c1850240962';               

		req.setEndpoint(url);
		req.setBody(body);
		req.setmethod('POST');
		httpresponse res= new httpResponse();
		res=p.send(req);
		result=res.getbody();


	}
       
}

Please check below trailhead module for more information
1) https://trailhead.salesforce.com/en/modules/apex_integration_services/units/apex_integration_rest_callouts

Let ys know if this will help you
 
raju p 4raju p 4
Hi, Thanks sir ,now its working..