+ Start a Discussion
csbaacsbaa 

Call Apex Webservice from other application

Hello Helper

I  have a question  about the design ans usage  of Apex Webservice  

I  have to write a  webservice in apex  which  will  be called  from a Biztalk application

I know how  to create  the Webervice.

What  is  do not  know  is  who  should  care about  Login to Salesforce org?

The Web service class  has  to contain a method  for Login  ?
OR
the caller  of the Web Service  has to take  care of  logging first to the Salesfoce org then call  my Webservice ?

what  is  the best practice here?

I preffer to  let this task  at  user side  but I am not  sure this  is a reasonable  approach

Thanks  in advance
Csbaa
  
Best Answer chosen by csbaa
kaustav goswamikaustav goswami
If you are only looking to update some account records then why is it necessary for you to write an apex class and expose it as webservice. You can just execute the update call and pass in the necessary information.

However, let me try to explain the steps.

Step 1 - Write the logic to update the accounts in the apex class.

global class ExposedServiceToUpdateAccounts {
    // your methods here
}

Step 2 - Download the enterprise wsdl and the wsdl for the apex class.

Step 3 - Consume the wsdl using web service connector (if you are using java)

Step 4 - use the connection object (object as in instance of a class not a salesforce object) to log in and retrieve the session id.

Step 5 - Call the apex service and use the session id in the header that you had retrieved in the previous step.

Thanks,
Kaustav

All Answers

kaustav goswamikaustav goswami
Hi,

The apex class that you are going to expose as webservice does not need to handle login functionalty separately. To login you will have to excute the normal login call using the connection object and then pass on the returned session id to the method from where you are calling the apex webservice.

Thanks,
Kaustav
csbaacsbaa
Thanks Kaustav

Let me see if  I understand properly
I have to  write Webservice  used by  a customer.  The webservice functionality is simple. It updates  some Account records

If  I  do not  provide the login inside my webservice how  customer  will  have access to "Connection object"?

Where connection  object reside?  How  customer access the Connction class/object?

Why  sessionId  is needed?


Regards
csaba 






 
kaustav goswamikaustav goswami
If you are only looking to update some account records then why is it necessary for you to write an apex class and expose it as webservice. You can just execute the update call and pass in the necessary information.

However, let me try to explain the steps.

Step 1 - Write the logic to update the accounts in the apex class.

global class ExposedServiceToUpdateAccounts {
    // your methods here
}

Step 2 - Download the enterprise wsdl and the wsdl for the apex class.

Step 3 - Consume the wsdl using web service connector (if you are using java)

Step 4 - use the connection object (object as in instance of a class not a salesforce object) to log in and retrieve the session id.

Step 5 - Call the apex service and use the session id in the header that you had retrieved in the previous step.

Thanks,
Kaustav
This was selected as the best answer
csbaacsbaa
thanks Kaustav

This is  what I was looking for

So the connection class  resides  in the enterprise wsdl  

to answer  your  first question
It it not me  who  need the Webservice
my  customer asks for this approach 

they also asked to rpovide  login functionality  but  I  will push this back

they can access enterprise wsdl  and use the Connection  class to log  into te org  then call my webservice  class


Thankds again
csaba