You need to pass in a Session ID that has API access. You can get this Session ID any way you want, including SOAP login() (see Setup > Develop > API for the WSDL files), SAML authentication via Single-Sign On (SSO), the Session ID from a Workflow Outbound Message, or any of the OAuth flows (Web Server, Client, or Username-Password). You provide the Session ID through the SessionHeader provided by the WSDL.
You'll want to check the appropriate documentation for your chosen method of logging in. The SOAP login() and the OAuth Username-Password flows require directly handling the username and password, while the other methods handle the login through other means, such as logging in through a WebForm.
First you need to set your endpoint
of your server.
- Endpoint URL (Sandbox)->
https://test.salesforce.com/services/Soap/u/35.0
- Endpoint URL (Production)->
https://login.salesforce.com/services/Soap/u/35.0
Set your headers
as below:
- SOAPAction-> ""
- Content-Type-> text/xml
And finally Body
. Replace Login Id and Password with actual credentials:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:partner.soap.sforce.com">
<soapenv:Body>
<urn:login>
<urn:username>Login ID</urn:username>
<urn:password>Password</urn:password>
</urn:login>
</soapenv:Body>
</soapenv:Envelope>
In response, you will get SessionId
.
Once you've SessionId
, set your endpoint URL as follows:
https://domain_name.my.salesforce.com/services/apexrest/YourWebServiceName
Again set Headers
as follows:
- Authorization-> Bearer
- Content-Type-> application/json
And Body
:
{
"name":"ABC"
}
Best Answer
A web service inside salesforce can:
You can call a static method in a restResource annotated method just like any other class. The only caveat is that the method cannot use or reference anything in the RestContext or RestReponse classes as they would be unavailable from a trigger...The annotation just allows the method to be mapped as a rest resource available to external systems
Basically treat it like any other static method, unless it utilizes the Rest classes in the method then you would treat it like any other callout
Consider this example:
you would simply use
mytestRest.myMethod(<AN ACCOUNT ID>);
in your trigger directlyHowever if this line exists in your method:
RestRequest req = RestContext.request;
Then you will not be able to call the method directly unless you account for the possibility that RestContext or req could be NULL everywhere it is used in the method. (I am not 100% sure if RestContext would dereference null error if called directly or if the RestContext.request would just return null)