You need to sign in to do that
Don't have an account?
Java - Update an Array of Accounts Previously Selected
In Java using a partner WSDL for the API:
I'd like to run a query, selecting several accounts based on the value of a particular field and then clear a few fields on the Account object for that list of accounts that was previously selected.
Do I need to iterate through the list of accounts and update them one at a time or can I code something similar to the Apex language that allows me to update all the accounts with one line of code?
APEX Example
global void execute(Database.batchableContext info, List<Account> scope){
List<Account> accsToUpdate = new List<Account>();
for(Account a : scope){
a.name = 'true';
a.numberOfEmployees = 69;
accsToUpdate.add(a);
}
update accsToUpdate;
}
Hi Dinesh,
I added the line setting the type to Account but that didn't really fix the issue. I did find a line of code for casting an array which a co-worker was able to help me utilize (he is a "true" java developer, not a part timer like me).
String[] stringArray = Arrays.copyOf(objectArray, objectArray.length, String[].class);
By using the example line of code above, we were able to correclty convert the list. I changed some of the variables in the code from previous updates to make things clearer. This works!
I do sincerely appreciate your assistance and encouragement!
Thanks,
Tom
All Answers
Yes ,
The Force.com web services have also Update method and it takes Array of sObject as argument.
But the difference is that you need to do the Login Call to establish the session between the client application and the SFDC , and need to initiate instance of SOAPBindingStub through which you need to use the Update method.
Please refer to the Force.com web services API guide ( available at http://wiki.developerforce.com/index.php/Documentation) and sample code.
Thanks,
Dinesh Nasipuri
dinesh.nasipuri@gmail.com
Thanks, Dinesh!
I appreciate your response. I've searched around in the web services documentation and elsewhere today as I did previously but I still am not able to find an example. It helps to know that it's possible and I'm not wasting my time. But would you happen to have a simple example? Thanks!
This is the example for JAVA , available in the Force.com web service API guide , whare binding is an instance of SoapBindingStub , need to set up by Login call.
Thanks and Regards,
Dinesh
Thanks again, Dinesh. The example was not quite what I was looking for but it does definitely help.
Maybe you can help further. Let me run the code below by you as it illustrates more precisely what I'm trying to accomplish.
I can compile this code using either of the two SaveResult [ ] lines of code but both cause errors when I try to run the program.
error message: java.util.ArrayList cannot be cast to com.sforce.soap.partner.sobject.SObject
Can you help or provide some clues for this last line of code that is currently commented out above?
You are almost there.
Just need to put a line ,
clearReinAccount.type = "Account";
To set the which SObject type you are using , Account or Contact or some thing else.
Thanks,
Dinesh
Hi Dinesh,
I added the line setting the type to Account but that didn't really fix the issue. I did find a line of code for casting an array which a co-worker was able to help me utilize (he is a "true" java developer, not a part timer like me).
String[] stringArray = Arrays.copyOf(objectArray, objectArray.length, String[].class);
By using the example line of code above, we were able to correclty convert the list. I changed some of the variables in the code from previous updates to make things clearer. This works!
I do sincerely appreciate your assistance and encouragement!
Thanks,
Tom