+ Start a Discussion
Micky MMicky M 

Web Service

Hi all,

Could anyone help me, i need to call a salesforce web method from java, ive got the code to connect to salesfroce and ive genterated the jars from my wsdl's using wsc. So im at the point where i can connect and run soql statements against salesforce and get results back and process them. But i need to be able to call a web method directly rather than run soql. Does anyone have any code to do this?

Thanks
ShashForceShashForce

You can use the "Retrieve()" call to get a single record using the record's ID, instead of the Query() call: http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_calls_retrieve.htm#topic-title

Another way is to write your own APEX web service methods in salesforce: https://developer.salesforce.com/page/Apex_Web_Services_and_Callouts

Micky MMicky M
Hi yeah thanks thats pretty much what ive already done. Ive got code at the moment like this :

QueryResult queryResult = connection.query("Select id, FirstName, LastName, Account.Name from Contact WHERE AccountId != null");

but ive written some web methods in apex and i want to call those methods from java.
ShashForceShashForce
You should generate Apex WSDL for those classes you've written and create jars from the WSDL: https://help.salesforce.com/htviewhelpdoc?err=1&id=dev_wsdl.htm&siteLang=en_US
Micky MMicky M
Yeah ive already done that, im after the code that says here's how you call the method really.
ShashForceShashForce
This should help then: http://manhntbkit.wordpress.com/2013/09/26/notes-web-services-in-salesforce/
Micky MMicky M
ah thanks! thats almost it athough i get this:

com.sforce.soap.DataWarehouseContractIvoicesWebservice.GetContractIvoice_element do you know what the _element bit is rather then com.sforce.soap.DataWarehouseContractIvoicesWebservice.GetContractIvoice ?

thanks
Micky MMicky M
sorry that was me being dumb, ok the code i have now looks like this :

try
  {
   com.sforce.soap.DataWarehouseContractIvoicesWebservice.SoapConnection soap = new com.sforce.soap.DataWarehouseContractIvoicesWebservice.SoapConnection(config);
   soap.setSessionHeader(config.getSessionId());
   System.out.println("Session header in query invoice = " + config.getSessionId());
   MCS_Contract_Recurring_Service_Invoice__c results = soap.getInvoiceDetails("a2CM0000000GGyhMAG");
   System.out.println(results.getId());
  }
  catch (ConnectionException ex) {
   Logger.getLogger(SalesforceMethods.class.getName()).log(Level.SEVERE, null, ex);
  }

but im getting this error?

com.sforce.ws.SoapFaultException: No operation available for request {http://soap.sforce.com/schemas/class/DataWarehouseContractIvoicesWebservice}getInvoiceDetails

any ideas?

thanks