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
Nelson Chisoko 8Nelson Chisoko 8 

Connecting to Salesforce Via Web Services

Hello Guys

Im a bit of a newbie here so I need your help. I am currently working on a POC on Salesforce and I want to know what the best way is to go about connecting to that salesforce account, creating, updating, or deleting records via a third party api. I dont want to build a java app or anything to do so. It should be like a remote call to do what I need to do to the objects.

Any reference to documentation I can look at or guides will be appreciated
Best Answer chosen by Nelson Chisoko 8
Saurabh Kulkarni 20Saurabh Kulkarni 20
Hello Nelson,

You can use the Webservices to do the operation on Salesforce Objects.. For this you must have to write a Webservice in your Salesforce instance which can generate a WSDL file, which can be further consumed by third party applications, so that these applications can make a call to the methods of Salesforce webservice...

For this approach you can check the below link..
https://developer.salesforce.com/page/Apex_Web_Services_and_Callouts

Regards,
Saurabh 

All Answers

Saurabh Kulkarni 20Saurabh Kulkarni 20
Hello Nelson,

You can use the Webservices to do the operation on Salesforce Objects.. For this you must have to write a Webservice in your Salesforce instance which can generate a WSDL file, which can be further consumed by third party applications, so that these applications can make a call to the methods of Salesforce webservice...

For this approach you can check the below link..
https://developer.salesforce.com/page/Apex_Web_Services_and_Callouts

Regards,
Saurabh 
This was selected as the best answer
Nelson Chisoko 8Nelson Chisoko 8
Hello Saurabh

I managed to expose some GET and POST methods as Web Services to connect to my SF account. Now I used the workbench to do the testing and it work. However now if now the person trying to access these services had to do it..essentially he/she would have to create some form of workbench with tokens etc to connect to my SF account from their systems right? If thats the case what is the best way to go about settin a client that can access these Apex to Web Services methods using oAuth?
Saurabh Kulkarni 20Saurabh Kulkarni 20
Well, Salesforce provides Partner and Enterprise WSDLs OOTB, which you can use to get logged in to the Salesforce instance.
You can use anyone of them.. I would prefer to use Partner WSDL, as it is more flexible and dynamic.

For this approach, below will be your steps:

1) Download partner WSDL from your salesforce instance from Setup -->Develop -->API -->Partner WSDL
2) Once you have the Partner WSDL, use the 'Login' method to get logged in to your Salesforce instance.. This login method will retutrn a Session ID.
3) Use the session ID generated in the next call i.e. while calling your custom webservice.

You can also use SAOP UI 2.0 application to do the testings of your webservices.

Best Regards,
Saurabh
Nelson Chisoko 8Nelson Chisoko 8
Hello Saurabh

Thank you for the swift response. I am a bit new to this thing so some of the steps Im not sure what to do. If I download I get the WSDL but then how do I use the Login method etc to do so. I assume there is a template somwhere in terms of code that I will use to set this up to make the login and then now start my calls to the exposed methods I set up. I just took a look at SOAP UI, it seems like a good program. What approach would you reccommend I take. Do I use the first instructions or the SOAP UI thing

Regards
Nelson
Saurabh Kulkarni 20Saurabh Kulkarni 20
Hello Nelson,

If you are looking for testing purpose then, I would prefer to use the SOAP UI, as this gives simpler way to call the webservices..
You just have to create new projects by browsing the WSDLs... Once you create a project you can see the methods that can be called and you can do your stuff.. 
But if you have a third party application and you are looking to call the webservices, then there can be different ways to call the webservices, its on your app and what it supports..
I know one of the way, which is writing a simple java class which can call the webservices...

One thing is important in all the cases, which is you must have to use the Partner WSDL for your first call to get session ID and use this session ID to further call your custom webservice.. Now the ways can be different to do this stuff..

Best Regards,
Saurabh 
Nelson Chisoko 8Nelson Chisoko 8
Hello Saurabh

Im leaning more towards a third party application. It should support oAuth, so I would essentially wanna build a java program that will call and get the session ID to further call my custom web service. Could you please provide me a sample java class that can connect to a SF Instance and get those Session IDs and call my web services like URI "/services/apexrest/recruiting/v1/" and invoke a method like
@HttpPost
	global static String createJobRequisition(String name, String industry) {
		Job_Requisition__c jr = new Job_Requisition__c(
			Name = name,
			Industry__c = industry);
		insert jr;
		return jr.Id;
	}

Or if its too much perhaps documentation that can help me build that. The key thing for me is using oAuth to connect to the service using that java class. I hope this makes sense

Regards
Nelson
 

Saurabh Kulkarni 20Saurabh Kulkarni 20
Hello Nelson,

To call the Webservice through Java you need to generate the jar files of your WSDLs...
Please follow the below steps....
1. Get wsc-23.jar (you can google for this)
2 Make sure you have defined the java path, or just Set your java path using following three commands:

set PATH=
set JAVA_HOME=c:\Java\jdk1.6.0_21
set PATH=%JAVA_HOME%\bin

2. Put your WSDL files (partner & Custom) and wsc-23.jar in a folder and execute the following two commands:

java -jar wsc-23.jar PartnerWSDL.xml TST_partner.jar
java -jar wsc-23.jar Custom_WebService.xml Custom_Webservice.jar

where text in bold are the WSDL file names.

3. As a result, these commands will give you two jar files in the same folder. One for the partner WSDL and one for the Custom WSDL.
4. Now create a new java project and import all the three jar files (wsc-23.jar , TST_partner.jar & Custom_Webservice.jar) as external jar files in the same java project.

now once you have done all these steps... You can follow below lonk which can tell you about writing a java class...
https://manhntbkit.wordpress.com/2013/09/26/notes-web-services-in-salesforce/

Best Regards,
Saurabh