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
CodeTalkerCodeTalker 

Apex vs. normal API Web Services

 
Hi Everyone,
 
We have written a service that connects to SF to download accounts, analyze them, and then upload new leads. This was done before Apex code came out using the SF Java API.
 
Now Apex code is out. I have written apex classes which do the same thing (upload leads, download accounts.)
 
I have read through the Apex Langauge Reference several times too. But I am still a little confused about
when to use Apex code.
 
1. Should apex code be used for SOQL queries or DML statements instead of the API?
 
2. In a web services scenario, does Apex code have any advantages over the API? Is it faster?
 
3. Also is my (simple) apex code optimized for uploading leads? Or is there a better way?
 
Code:
webService static void saveLeads(Lead[] leads){insert leads;}

 

Message Edited by CodeTalker on 09-24-2007 01:52 PM

Message Edited by CodeTalker on 09-24-2007 01:52 PM

mtbclimbermtbclimber
1. If all you want to do is simple SOQL and DML then you should simply utilize the API.

2. If you have a process that requires multiple operations to complete and you want them all to succeed and if any one fails rollback then Apex Webservices are what you need. There is no other way to implement transaction support.

If you have a client that does multiple requests to the API in order to provide one interaction/experience for a user then you can typically reduce those multiple operations to one aggregated Apex webservice. That way you make one round-trip to salesforce for all the information you might need from multiple queries and/or DML.

3. That webservice adds zero value over the API. In fact it reduces value because you will not receive the saveResults to know whether or not there were any failures.
CodeTalkerCodeTalker

Thank you for helping me with my questions.

2. Can you give me a high level example of a multiple operation/multiple query type process? I don't know too much about CRM and sales.

1. In our own application, We have a service that mimics SOQL underneath the covers. The user can then send a "view" of accounts (or some other sobject) over to our side. We use those accounts to produce  new leads which get uploaded back to SF. So it seems to me, the interaction with SF is pretty simple in our case.

 3. Yes you're right. That was just a quick method to practice some DML in apex code.  

 

 

 

Message Edited by CodeTalker on 09-24-2007 06:02 PM