0

I am newbie. I'm trying to pass in a List of recordids through the use of a custom button from a List View in classic. The parameters section of the sforce.apex.execute method is not right.

{!REQUIRESCRIPT("/soap/ajax/50.0/connection.js")}

{!REQUIRESCRIPT("/soap/ajax/50.0/apex.js")}

var ids = {!GETRECORDIDS( $ObjectType.Request__c )};

sforce.apex.execute("UpdateWireStatus","getWireDetails",{ids});   <<<---??

window.location.reload();

Here is the Apex Class that will receive the List of Ids.

 global class UpdateWireStatus {

 @TestVisible
private static Boolean testException = false;

webService static void getWireDetails( List<Id'> requestIdList) {
            
System.debug('ID:' + requestIdList);
           
 List<Request__c> requestRecordList = PershingHelper.getRequestRecords(requestIdList);

            for (Request__c thisRequest : requestRecordList) {
                Pershing.getWireDetails(thisRequest);
            }

            try {
                if(testException) {
                    throw  new RTSCallout.ApiException('Test Exception');
                }
                Database.update(requestRecordList, false);
            }
            catch(Exception e) {
                System.debug('Error updating Request: ' + e.getMessage() + ':' + e.getStackTraceString());
            }
        }
    }
5
  • What error are you getting?
    – fred
    Jul 25, 2023 at 13:32
  • Try doing {"ids": ids} instead of just {ids}
    – fred
    Jul 25, 2023 at 13:43
  • @fred { "ids": ids } and {ids} are identical.
    – sfdcfox
    Jul 25, 2023 at 16:35
  • @sfdcfox I know but isn't that quite a recent change? I thought maybe since it's a classic Javascript button it might not be valid syntax? Happy to be corrected!
    – fred
    Jul 25, 2023 at 16:37
  • 1
    @fred This syntax came out with ES6, around 2015. Classic buttons use whatever JavaScript is supported by the browser, and all Salesforce-supported browsers are new enough to support this.
    – sfdcfox
    Jul 25, 2023 at 16:46

1 Answer 1

1

The parameter names have to match:

webService static void getWireDetails( List<Id> requestIdList) {

...

var requestIdList = {!GETRECORDIDS( $ObjectType.Request__c )};
sforce.apex.execute("UpdateWireStatus","getWireDetails",{requestIdList});

Note that this is case sensitive.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .