I need to create a custom button on the list view of a custom object. When user selects multiple records on the list view and I need to send those record IDs to be processed by a batch process (I chose batch process because user may possibly select lot of records from the list view.But if someone has other pointers on this design, feel free to comment).
After googling around, i figured this is what i have to do –
Button Click -> call a web service -> web service calls my batch process
My problem is with the first step. From the javascript button, i am not sure how to pass those record IDs to the web service. If i can pass it as a string or something, i can then do further manipulation in my batch process to covnert it to Set.
My javascript knowledge is limited to googling for less than 24 hrs, and i am a relatively new developer, so pardon me if these questions are conceptual. I did my homework best to my capabilities before posting question here.
Code for javascript button on the list view-
{!REQUIRESCRIPT("/soap/ajax/30.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/30.0/apex.js")}
var records = {!GETRECORDIDS($ObjectType.Acquisition_POC__c)};
var result = sforce.apex.execute("acquisitionListViewDocusign","callAcquisitionBatch",{receivedAcquisitionIDSet : records});
Needless to say, that last line doesn't work. It throws errors.
Code for my web service
global with sharing class acquisitionListViewDocusign {
webService static String callAcquisitionBatch(String receivedAcquisitionIDSet) {
//If i can get the parameter properly, i can do more stuff, such as call my batch process
return receivedAcquisitionIDSet;
}
}
So how do i pass that javascript array (in the custom button) as a parameter to a webservice.
If anyone has a completely different design input, please let me know.
Best Answer
Thanks Keith. It worked. Now i feel stupid. It was something so simple. Overnight, i got it to work by using JSON.stringify() in the javascript button, and then deserializing it in my batch class. Guess i needed a good night sleep.
I will post my complete working code here just in case someone needs to look at it in future.
Javascript button on the list view
Button calls a web service. Code for web service -
Web service calls the batch job (as obvious from above code). Code for batch job-
I would still like to ask again - to pass multiple records via list view button, into a batch process ..... is web service the only way? Is there any other way? Infact, from what i found through google, in order to call any class via javascript button, we have to go through web service. Is that true?