Interview Questions on Salesforce API’s

 Question and Answers:

I am working on a salesforce feature, where we are trying to expose a single web Service method in a custom class to a “Partner” so they can generate leads.

The class/method has been created/tested and functions as expects, so we are working on implementation.

I have been poring over all of Salesforce’s Web Service documentation and cookbook recipes, but everything I see only talks about using either the Enterprise or Partner WSDL files, which would give them more access then I believe should be required.

If I import the WSDL file that is generated off the class itself, I have access to the methods, but I can’t seem to find any way to log in (using their examples as reference).

Based on the above scenario we can have 2 questions for it.

1) Do I really need to give full access to my instance to expose a single method?

2) What is the bare minimum I need to provide?

Answer: The WSDL itself is just a definition of the web service and does not control actual access to your org. To get access to your org, a session id must be included in each request to the web service. Session ids are tied to a given user in your org, so you can also control what they can access by giving them their own profile and locking down access to only what they need to get to. The profiles are associated with objects/fields, not the web services themselves, think about what they will need to access in terms of data, because they could always use that same session to access other web services. There are also Apex class-level access controls on the profile, but this doesn’t stop them from doing the same data operations through the SOAP APIs, so make sure you have their profile only expose what they need access to and that will be enforced everywhere.

As far as obtaining the session id, it somewhat depends on how you are interfacing with them and what their application is like. In general, the recommended way is to use OAuth (called “Remote Access” in Salesforce Help), which will make it so usernames and passwords don’t have to be used in their application, but are rather sent directly to Salesforce by the end user. There are a few different flows to choose from depending on the app and are explained in Help. The REST API doc has a nice intro to using OAuht to get the session id (aka “token” in OAuth). Speaking of REST, you might even consider using the new Apex REST API, which allows you to make similar custom web services from Apex, but with REST interfaces.

2) How to use external WSDL in Salesforce application?

Enterprise WSDL
A strongly typed WSDL for customers who want to build an integration with their salesforce.com organization only.

Partner WSDL
A loosely typed WSDL for customers, partners, and ISVs who are building client applications for multiple organizations. It can be used to access data within any organization.

3) Difference between REST and SOAP API’S?

Varies on records that can be handled. Generally if we want to access less number of records we go for REST API.

4) Which will you use to create the fields or objects? Select two choices,

  1. Force.com IDE
  2. In applications
  3. Force.com Meta data API
  4. Visual force Pages

Answer : 1 & 3.

 

5) How to fetch data from another Salesforce instance using API?

Answer: Use the Force.com Web Services API or Bulk API to transfer data We this this is a great job for the Bulk API. 

 

6) What is the use of Metadata API?

Answer: We use Metadata API to retrieve, deploy, create, update or delete customization information, such as custom object definitions and page layouts, for your organization. This API is intended for managing customizations and for building tools that can manage the metadata model, not the data itself. To create, retrieve, update or delete records, such as accounts or leads, use data SOAP API  or REST API.

The easiest way to access the functionality in Metadata API is to use the Force.com IDE or Force.com Migration Tool. These tools are built on top of Metadata API and use the standard Eclipse and Ant tools respectively to simplify the task of working with Metadata API. Built on the Eclipse platform, the Force.com IDE provides a comfortable environment for programmers familiar with integrated development environments, allowing you to code, compile, test, and deploy all from within the IDE itself. The Force.com Migration Tool is ideal if you want to use a script or a command-line utility for moving metadata between a local directory and a Salesforce organization.

 

7) How to call Apex method from a Custom Button?

Answer: An Apex callout enables you to tightly integrate your Apex with an external service by making a call to an external Web service or sending a HTTP request from Apex code and then receiving the response. Apex provides integration with Web services that utilize SOAP and WSDL, or HTTP services (RESTful services).

Example : Stock Exchange mentioned In this Blog for SOAP API.

 

8) What are callouts in Salesforce?

Answer: An Apex callout enables you to tightly integrate your Apex with an external service by making a call to an external Web service or sending a HTTP request from Apex code and then receiving the response. Apex provides integration with Web services that utilize SOAP and WSDL, or HTTP services (RESTful services).

 

9) What is the use of Chatter REST API?

The Chatter API (also called Chatter REST API) lets you access Chatter information via an optimized REST-based API accessible from any platform. Developers can now build social applications for mobile devices, or highly interactive websites, quickly and efficiently.

 

10) How to fetch data from another Salesforce instance using API?

Answer: Use the FORCE.COM WEB SERVICES API or BULK API to transfer data We this this is a great job for the Bulk API. 

 

11) How to implement Salesforce to Salesforce connection?

Answer: Enable SF to SF connection in Customize and then invite other SF company. Both have to accept invitation. Then we can import the Partner API into Apex. You can then call the query and insert operations on that service to communicate with another org.

 

Note: Test methods cannot be used to test Web service API

 

Common Errors in Salesforce API’s

Error import com.sforce.soap.enterprise

Resolution:

Its a common error in Webservice api.
To avoid this error, you have to use the below syntax to create enterprise.jar.

Code:
java –classpath pathToJAR/wsc-20.jar com.sforce.ws.tools.wsdlc pathToWsdl/WsdlFilename
pathToJar/JarFilename

Example:

java -classpath wsc-20.jar com.sforce.ws.tools.wsdlc enterprise.wsdl.xml enterprise.jar

The above code generates a jar file named ‘enterprise’.

You should include this jar file to avoid errors.

 Be Sociable LIke it or Share it.

 

 

2 comments

  1. Thanks, It is very helpful.

    1. Just let me know if you find any new interview questions

Leave a comment