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
Farhad KeywanFarhad Keywan 

Problem in Integration between java and Salesforce

Hi,

 

I want to get data from MySql through java program and call that java program from salesforce.

what steps are required and which type of webservice is suitable in salesforce? 

 

Should i use SOAP or Rest web services?

 

Thanks,

Soni

Tejpal KumawatTejpal Kumawat

Hi Farhad,

 

You can use according your requirement, But i think it is easy through  Rest web services..

 

You get 

public static String SALESFORCE_CLIENTID = "";
public static String SALESFORCE_CLIENTSECRET = "";

 

by folowing step

 

App Setup -->Develop--> Remote Access


 

 

This is Snippt for connection for Java & salesforce:

 

 

public String doConnection() {
String token = null;
try {
DefaultHttpClient restClient = new DefaultHttpClient();
// HttpClient restClient = new HttpClient();
HttpPost postMethod = new HttpPost(SF_PREFIX_URL + SF_OAUTH_URL);
List<BasicNameValuePair> formparams = new ArrayList<BasicNameValuePair>();
// Set up the form parameters as this flow uses the POST request
// The client_id/client_secret is obtained by configuring the
// REMOTE_ACCESS setting in your org
formparams.add(new BasicNameValuePair("client_id",SALESFORCE_CLIENTID));
formparams.add(new BasicNameValuePair("client_secret",SALESFORCE_CLIENTSECRET));
formparams.add(new BasicNameValuePair("username",SALESFORCE_USERNAME));
formparams.add(new BasicNameValuePair("password",SALESFORCE_PASSWORD + SALESFORCE_SECURITYTOKEN));
// The grant_type = password is required for this flow
formparams.add(new BasicNameValuePair("grant_type", "password"));
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(formparams,"UTF-8");
postMethod.setEntity(entity);
ResponseHandler<String> responseHandler = new BasicResponseHandler();
String response = restClient.execute(postMethod, responseHandler);
// * Do Parsing Here and fetching OAUTH TOKEN

JsonNode actualObj = parseResponse(response);

token = actualObj.get("access_token").asText();
SF_PREFIX_URL = actualObj.get("instance_url").asText()+ "/services";

} catch (Exception e) {
e.printStackTrace();
token = null;
}
return token;
}

 

 

--------------------
If a reply to a post answers your question or resolves your problem, please mark it as the solution to the post so that others may benefit.

Thanks