+ Start a Discussion
BangoBango 

Testing REST API

Hello experts :) I created the following APEX Class in my Dev Org:

 

@RestResource(urlMapping='/createCase/*')
global with sharing class RESTCaseController 
{

@HttpPost  
global static Void createNewCase()
{
Case c = new Case();
c.OwnerId = '005i0000001uqEm';
c.AccountId = '001i000000RsOOS';
c.Subject = 'SOAP Test';
c.Status = 'New';
insert c;
return;
}

}

 

 

So the endpoint URL is https://na15.salesforce.com/services/apexrest/FieldCase

 

There will be a a third party application that will send SOAP messages to that end point.


I would like to test it and see if it'll create a case for me :) Any help is much apreciated (By the way, I'm new to this so bare with me :) )

sfdcfoxsfdcfox
Don't confuse SOAP and REST. If you're sending SOAP messages, you need the "webservice" keyword in order to enable it as a SOAP target. You can choose to access this class via REST, using any common tool such as the Developer Workbench (workbench.developerforce.com), curl, or most any other REST-capable tool.
BangoBango
Thank you for the reply. Could you please clarify what I need to do to enable it as a SOAP target? I'm new to this, thanks again.
sfdcfoxsfdcfox
global with sharing class SOAPCaseController {
    webservice static void createNewCase() {
        // Code here
    }
}

Once saved you can click on the class list and generate a WSDL for the class.

 

 

BangoBango

Thank you :) I just did that and generated the WSDL, now what should I do? :)

 

Is it that I povide the WSDL to the SOAP msg sender or do I provide a URL like before with the REST API?

 

Sorry for bothering you, I'm new at this and trying to learn, thanks in advance :)

sfdcfoxsfdcfox
The WSDL contains the necessary URLs and message contracts. A URL by itself would be nearly useless for SOAP, while in REST, it would be all you need to provide.
BangoBango

Thank you :) I appreciate you helping me with this. I received the requirements yesterday for their SOA msg sender and they said that we need to provide them with an IP address and a port number. Is there a way to get that info from the WSDL file or somewhere else? Thank you in adbvance.

sfdcfoxsfdcfox
The IP address will be one of salesforce.com's IP addresses (see http://help.salesforce.com/apex/HTViewSolution?id=000003652&language=en_US), the port will always be 443 (HTTPS).
BangoBango

Thank you for the quick response :) How will SalesForce know where to send the message if all I give the sender an IP address and a port number that everybody uses?

 

I guess I'm confused on how it'll be directed to the controller that I have rather than one that some other Org has. Thank you in advance.

sfdcfoxsfdcfox
You must first authenticate and receive a session ID and API URL. The system will know which organization and controller you are intending to access based on this information. To login, you will need to import the Partner or Enterprise WSDL in order to instantiate the login() function (Setup > Develop > API).