+ Start a Discussion
ssssssss 

how to use webservices in salesforce

Hi All,

 

I am new to webservices concept.i want to do sample app with webservices using java or apex

Plz tell me the requirements for the sample app and step by step process to finish the sample application.

 

Plz help me...

 

Thanks in advance,

manju

_Prasu__Prasu_

You want to consume web service written in Java in Salesforce Apex code or Vice a versa?

 

ssssssss

Thanks for ur reply,

 

what ever it may be i want to develop a sample app on webservices in salesforce.I am exploring on this topic but i didnt get any step by step process.i know basics on salesforce,apex,java.So i am using this concepts.Now i am working on salesforce.So iam trying to learn webservices.Plz what are the requirements software for this webservices sample app.

Plz tell me step by step processes and example code.

 

Waiting for ur reply....

 

Thanks in advance,

Manju.

_Prasu__Prasu_

Hello Manju,

 

Its still not clear to me what really you want to develop.

But i think following link will be helpful for you.

Apex_Web_Services_and_Callouts

 

Thanks,

ssssssss

 

Use the Force.com Web Services API to create, retrieve, update, or delete records in
Force.com from any external system that supports SOAP-based Web services, such as
Java, .NET, or PHP client applications. With more than 20 different calls, the API also
allows you to maintain passwords, perform searches, retrieve metadata information about
objects and more.

 

hi Prasanna,

 

I want to use Force.com Web Services API to create, retrieve, update, or delete records inForce.com from any external system that supports SOAP-based Web services using java.....

 

Plz tell me...

_Prasu__Prasu_

You will need to study the Integration docs:

You can consume Salesforce API's in many platforms/langs like .NET, Java, PHP, flex

 

Following link will provide you the docs as well as Sample codes: Integration

 

If you need quick start guide you can refer following sample code: Sample code

Abhinav GuptaAbhinav Gupta

I have created a wrapper project on top of Java(Apache Axis) Web Service Stubs for all Salesforce WSDLs. The project is named "Tolerado" and here is the link to it http://code.google.com/p/tolerado-salesforce-web-services-client-wrappers/wiki/GettingStartedGuide

 

You can try playing with it, using Tolerado is for sure simpler then usual WSDL2java Apache Axis stubs.

ssssssss

Thanks for ur reply,

 

I was trying to do the following steps.

 

*********************************************************************************

How to integrate Sales Force web services in Eclipse using Axis2 tool.

 

Solution: 

 

Page 1 of 10
Web Services Integration between Force.com and Java
Using Apache Axis2
Version No. 1.0
BodhTree Consulting Limited
1-8-617/2,Prakasham Nagar, Begumpet, Hyderabad 500016
Contents of this document are proprietary and confidential to BodhTree Consulting Limited. Please do not
copy or reproduce without prior written notice from BodhTree. If you see this document unattended please
forward this to BodhTree.
Page 2 of 10
I. Step ->
Generate WSDL from Salesforce.com Site:
1. Login into the salesforce.com site.
2. Go to Setup AppSetup Develop API.
3. Right click on “Generate Enterprise WSDL” and save the target as
“SalesForce.wsdl”.
Now your WSDL file of salesforce.com site gets ready.
II. Step ->
Create Stubs in Eclipse using Axis2 Tool: :
Note: Make sure to configure Axis2 plug in your Eclipse environment.
Page 3 of 10
1. File New Other Dynamic Web Project Create a project.(Eg:
SalesforceStubs)
2. Download Axis 2 Libraries from Apache Axis site and import those into the
current project.
3. Goto Project Menu properties java Build path libraries Add Library
User Library User Libraries New Add library name and libraries from
Axis 2 which we are downloaded. Ok.
4. Right Click on Project name New Other Axis2 Wizards Axis2 Code
Generator Next.
Page 4 of 10
5. Select Generate Java Source Code from WSDL file click Next.
6. Browse the wsdl file which you generated earlier from salesforce.com site and
then click Next.
Page 5 of 10
7. Select Custom in “Codegen option” and select “Generate Both with all classes for
every elements on schemas” check box and Click on Next.
Page 6 of 10
8. Select the output path location and click on Finish.
Then we have several packages with .java files in the java resources part of the project.
For example we can get the following packages.
com.sforce.soap.enterprise
com.sforce.soap.enterprise.fault
com.sforce.soap.enterprise.sobject
III. Step ->
Creating a Client Program to connect to Sales Force:
// SforceServiceStubClient.java
package com.sforce.soap.enterprise.client;
import java.rmi.RemoteException;
import org.apache.axis2.AxisFault;
import com.sforce.soap.enterprise.client.util.SforceLoginUtil;
import com.sforce.soap.enterprise.InvalidFieldFault;
import com.sforce.soap.enterprise.InvalidIdFault;
import com.sforce.soap.enterprise.InvalidQueryLocatorFault;
import com.sforce.soap.enterprise.InvalidSObjectFault;
import com.sforce.soap.enterprise.LoginResult;
import com.sforce.soap.enterprise.MalformedQueryFault;
import com.sforce.soap.enterprise.Query;
import com.sforce.soap.enterprise.QueryResponse;
import com.sforce.soap.enterprise.QueryResult;
import com.sforce.soap.enterprise.SessionHeader;
import com.sforce.soap.enterprise.SforceServiceStub;
import com.sforce.soap.enterprise.UnexpectedErrorFault;
import com.sforce.soap.enterprise.sobject.Account;
import com.sforce.soap.enterprise.sobject.SObject;
public class SforceServiceStubClient {
public static void main(String[] args) {
String username="xxxxxxxx";
String token="xxxxxxxxxxxxxxxxxxxxxxxxx";
String tokenPassword="xxxxxxxxx"+token;
try{
LoginResult loginResult = SforceLoginUtil.loginToSalesForce(username,
tokenPassword);
Page 7 of 10
SessionHeader sessionHeader = new SessionHeader();
sessionHeader.setSessionId(loginResult.getSessionId());
SforceServiceStub stub = new SforceServiceStub(loginResult.getServerUrl());
System.out.println("Connected to SF with the URL: " +
loginResult.getServerUrl());
Query query = new Query();
query.setQueryString("select Id, Name from Account");
QueryResponse queryResponse = stub.query(query,sessionHeader,null,null,null);
QueryResult queryResult=queryResponse.getResult();
System.out.println("Query has " + queryResponse.getResult().getSize() + "
records total");
SObject[] sObjects = queryResult.getRecords();
System.out.println("Account Details:");
System.out.println("----------------------------------------");
System.out.println("Account id Name");
System.out.println("----------------------------------------");
for (int i = 0; i < sObjects.length; i++) {
Account sObject = (Account) sObjects[i];
System.out.println("["+ sObject.getId() + "][" +
sObject.getName() + "]");
}
}
catch (AxisFault e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (UnexpectedErrorFault e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvalidIdFault e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvalidSObjectFault e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvalidQueryLocatorFault e) {
// TODO Auto-generated catch block
e.printStackTrace();
Page 8 of 10
} catch (MalformedQueryFault e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvalidFieldFault e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} // end of main
}
// Util program: SforceLoginUtil.java
package phani.sforce.soap.enterprise.client.util;
import java.rmi.RemoteException;
import org.apache.axis2.AxisFault;
import com.sforce.soap.enterprise.GetUserInfoResult;
import com.sforce.soap.enterprise.InvalidIdFault;
import com.sforce.soap.enterprise.Login;
import com.sforce.soap.enterprise.LoginFault;
import com.sforce.soap.enterprise.LoginResponse;
import com.sforce.soap.enterprise.LoginResult;
import com.sforce.soap.enterprise.SforceServiceStub;
import com.sforce.soap.enterprise.UnexpectedErrorFault;
public final class SforceLoginUtil {
public static LoginResult loginToSalesForce(String userName, String
tokenPassword){
LoginResult loginResult=null;
SforceServiceStub stub;
try {
stub = new SforceServiceStub();
// Salesforce user name
Login login = new Login();
login.setUsername(userName);
// Your password at Salesforce followed by your security token
login.setPassword(tokenPassword);
LoginResponse loginResponse;
loginResponse = stub.login(login, null);
loginResult = loginResponse.getResult();
GetUserInfoResult userResult=loginResponse.getResult().getUserInfo();
if(loginResult!=null){
Page 9 of 10
if(loginResult.getSessionId()!=null){
System.out.println("Welcome to "+ userResult.getUserFullName());
}
}else{
System.out.println("Login failure !!");
}
} catch (AxisFault e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (UnexpectedErrorFault e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvalidIdFault e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (LoginFault e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return loginResult;
} // end of method
public static LoginResult getLoginResult(LoginResponse response) throws Exception{
if(response!=null){
return response.getResult();
}else{
throw new Exception("Invalid Login Response");
}
}
public static LoginResponse loginToSalesForceAndGetResponse(String
userName, String tokenPassword){
LoginResponse loginResponse=null;
SforceServiceStub stub;
try {
stub = new SforceServiceStub();
// Salesforce user name
Login login = new Login();
login.setUsername(userName);
// Your password at Salesforce followed by your security token
login.setPassword(tokenPassword);
loginResponse = stub.login(login, null);
Page 10 of 10
}catch (AxisFault e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (UnexpectedErrorFault e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvalidIdFault e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (LoginFault e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return loginResponse;
} // end of method
} // end of class
IV. Step
Run the Client Program
Run the program SforceServiceStubClient.java.
Sample Output:
log4j:WARN No appenders could be found for logger
(org.apache.axis2.description.AxisService).
log4j:WARN Please initialize the log4j system properly.
Welcome to xxxxx
Welcome to Sf xxxxx
Connected to SF with the URL: https://ap1-
api.salesforce.com/services/Soap/c/17.0/00D9000000010gk
Query has 13 records total
Account Details:
----------------------------------------
Account id Name
----------------------------------------
[00190000002OSsmAAG][bodhtree]
[00190000002PrenAAC][anu]
[00190000002jtmlAAA][my new account]

Message Edited by Bodhtree on 11-17-2009 04:09 AM
***********************************************************************************************

But i was unable to configure Axis plugin into eclipse.I downloaded the following zar files

1.axis2-eclipse-codegen-wizard-1.4

2.axis2-eclipse-service-archiver-wizard-1.4

and i extracted.and i placed those files into 

eclipse-java-galileo-SR2-win32-->eclipse-->plugins-->

axis2-eclipse-codegen-wizard-1.4,axis2-eclipse-service-archiver-wizard-1.4.

i was trying to create dynamic project.But i i didn't get any option like Dynamic project.

 

Plz tell me how to do this application.and how to configure Axis plugin into eclipse.and the requirements softwares for this apllication .

 

Thanks in advance,

manju..

USUS

Hi !

 

     The article looking great

     Bye the by do you have any idea in accessing the " query results"  type

     Like getAttachments(): QueryResult,  getContacts():QueryResult etc.,

     Please let me know

 

Thanks in advance

US

 

  

 

harshasfdcharshasfdc

Hi 

 

i want to use salesforce webservices in order to pull data from applications whic are been developed in .net .i have generated wsdl file in .net and i imported wsdl file and a APEX CLASS tempuriOrg  is generated .i am unable to know how to use this apex class in order to map custom object .in order to display dashboards 

 

please give me some valuable information regarding this

 

thanks

harsha


Aravinthraj techresourceAravinthraj techresource

Hi

 

 

        I am new to salesforce how to use web services and how it works pls explain or reply it

 

Thanks

MagulanDuraipandianMagulanDuraipandian

http://www.infallibletechie.com/2012/11/java-to-salesforce-connection.html

 

If this solves your problem, kindly mark it as the best answer.

Regards,
Magulan
http://www.infallibletechie.com