+ Start a Discussion
lopezclopezc 

API calls

Hi All,

I have my Force.com IDE created and I would like to create classes that allow me to insert/update /delete data in salesforce database. Should I create just an Apex Class? Is it enough?

Thanks
Cris.
jpizzalajpizzala
Well, all depends on what you want to do.  If you are using Apex, yes, you will need to create an Apex class (or classes).  In order to execute the class(es), however, you will need to add Apex triggers that will fire when a record is created/updated/deleted/un-deleted.

Check out the following resources for more information:
lopezclopezc
Hi

Thanks for the docs, but I didn't explain very well what I want or I am trying to do. I would like to use the API in a client application. This application give a new contact with their details in a xml file and I would like to send it in a SOAP message to Salesforce to be able to insert it into my organization'data in Salesforce. I installed SOAPUI for testing but something is not working. I tried to do a loggin and here are the results:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:enterprise.soap.sforce.com">
<soapenv:Body>
      <urn:login>
         <urn:username>username</urn:username>
         <urn:password>pwd</urn:password>
      </urn:login>
   </soapenv:Body>
</soapenv:Envelope>

the response:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
   <soapenv:Body>
      <soapenv:Fault>
         <faultcode>soapenv:Client</faultcode>
         <faultstring>No operation available for request {urn:enterprise.soap.sforce.com}login</faultstring>
      </soapenv:Fault>
   </soapenv:Body>
</soapenv:Envelope>

I add the Enterprise WSDL to my project in SOAPUI. Sorry if I am talking about different things all the time but I just would like to update Salesforce database from my client application and I don't really know how to do it. I tried also with Java in Eclipse:

private boolean login() {
LoginResult loginResult = null;
SoapBindingStub sfdc = null;
try {
// Create binding object
sfdc = (SoapBindingStub) new SforceServiceLocator().getSoap();
// login
loginResult = sfdc.login("username", "password");
} catch (Exception ex) {
System.out.println("An unexpected error has occurred." + ex.getMessage());
return false;
}

System.out.println("Login was successful.");

// Reset the SOAP endpoint to the returned server URL
sfdc._setProperty(SoapBindingStub.ENDPOINT_ADDRESS_PROPERTY, loginResult.getServerUrl());

// Create a new session header object
// add the session ID returned from the login
SessionHeader sh = new SessionHeader();
sh.setSessionId(loginResult.getSessionId());
// Set the session header for subsequent call authentication
sfdc.setHeader(new SforceServiceLocator().getServiceName().getNamespaceURI(),
"SessionHeader", sh);


// get user info
try {
GetUserInfoResult userInfo = sfdc.getUserInfo();
} catch (Exception ex) {
System.out.println("An unexpected error has occurred." + ex.getMessage());
return false;
}

return true;
}
But the error is that LoginResult is an invalid Type ( LoginResult loginResult = null; ).
Which library should I import? What I am doing wrong?

Thanks,
Cristina.


Message Edited by lopezc on 06-02-2008 08:25 AM

Message Edited by lopezc on 06-02-2008 08:34 AM
SuperfellSuperfell
The API docs have a detailed walk through on getting up and running in java. For the SOAPUI problem, it sounds like you sent an enterprise API request to the partner API endpoint URL.
http://www.salesforce.com/us/developer/docs/api/index.htm
lopezclopezc
I manage to connect with the production server of Salesforce. However I have problems with sandbox.
the endpoint url I am using for production is http://www.salesforce.com/services/Soap/c12.0
the endpoint I am using for sandbox is https://test.salesforce.com/services/Soap/u/12.0

The error message is still

 <faultcode>soapenv:Client</faultcode>
 <faultstring>No operation available for request {urn:enterprise.soap.sforce.com}login</faultstring>

Is it connecting to the server? is there probably a problem with my account in test? Why is it working in production?

Thanks
Cris



Message Edited by lopezc on 06-03-2008 03:22 AM
lopezclopezc
hi,

I have also tried to connect to Salesforce through Eclipse. I have created my Dynamic Web project in Eclipse and I am trying now to log into Salesforce. The skeleton of my project contain 3 packages (com.sforce.soap.enterprise, com.sforce.soap.enterprise.fault, com.sforce.soap.enterprise.sobject) and I create my own package where I placed my main function:

package my_code;

import com.sforce.soap.enterprise.*;
public class main {

    /**
     * @param args
     * @return
     */
    public static boolean main(String[] args) {
        // TODO Auto-generated method stub
        LoginResult loginResult = null;
          SoapBindingStub sfdc = null;
          try {
            //    Create binding object
            sfdc = (SoapBindingStub) new SforceServiceLocator().getSoap();
            //    login
            loginResult = sfdc.login("username", "pwd");
          } catch (Exception ex) {
            System.out.println("An unexpected error has occurred." + ex.getMessage());
            return false;
          }

          System.out.println("Login was successful.");

.................

However, when I run my project in the server (click right on the main.java and "Run As" and "run on the Server"), Apache return an error message as following:

 

type Status report

message /Prj1/WEB-INF/classes/my_code/main.java

description The requested resource (/Prj1/WEB-INF/classes/my_code/main.java) is not available.


Should I create this main class?? How I do to log in Salesforce?

thanks
Cris

 

SuperfellSuperfell
The URL for the sandbox enterprise API https://test.salesforce.com/services/Soap/c/12.0
lopezclopezc
Thanks Simon!!

Now I can access to sandbox!!

I am trying to do exactly the same using Eclipse and using the API calls. I manage to create my client application and log into salesforce. However, for the login call, the parameter always starts with  http(s)://www.salesforce.com so I am always logging in salesforce production. I would like to log in Sandbox but I don't know which parameter I have to modify in my web application. How can I modify the endpoint url? where is this parameter initialize per default?

Could you help me in solving this?

Thanks,
Cristina.


Message Edited by lopezc on 06-04-2008 07:43 AM
kamalkamal
Hi, If u want to deploy contacts for which the information is in xml format then you have to use "metada Api calls to deploy the xml file....you have to package the xml file in proper folder structure and prepare a .zip file out of the folder structure and then deploy it using metadata api call"deploy()". for more infrmation look into the documentation of the declarative type calls of the metada Api .

Thanks
kamalakar rao