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
duubduub 

Error on Javascript sforce.apex.execute with Array being passed

Hi, trying to pass an Array into an Apex Class. As per Line highlighted. I can pass a single static account ID, and all works, it is just the array that is not working. Have also confirmed that there is data in the array.

 

When the button executes, I get this error

 

A problem with the OnClick JavaScript for this button or link was encountered:

{faultcode:'soapenv:Client', faultstring:'Unexpected element {http://soap.sforce.com/schemas/package/QueuedAccSingleManagement}done during simple type deserialization', }

 

 

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

     var records = {!GETRECORDIDS($ObjectType.Queued_Account__c)};
     var newRecords = [];
     var Acc_ID = [];


     if (records[0] == null)
     {
         alert("Please select at least one row")
     }
     else
     {
        for (var n=0; n<records.length; n++) {
        var c = new sforce.SObject("Queued_Account__c");
        c.id = records[n];
        c.queue_status__c = "Inactive";
        Acc_ID[n] = sforce.connection.query("select Account__c from Queued_account__c WHERE Id ='" + c.id + "'");

       newRecords.push(c);
     }
     }  

    sforce.debug.trace=true;
    if (sforce.debug.trace) { sforce.debug.log("{!$User.Id}");}
    result = sforce.connection.update(newRecords);
    sforce.apex.execute("QueuedAccSingleManagement", "removeMultiAccount", {acc:Acc_ID, userId:"{!$User.Id}"},null,true);

    window.location.reload();
}

NBlasgenNBlasgen

I'm not really sure about what the issues are with your code (I don't feel like debugging it), but there are a few things I'm questioning.

 

Why are you setting c.queue_status__c when it's never used?  And please make sure it wouldn't be something like c.fields.queue_status__c.  Normally only fields such as Id are in the main SObject (but this may not be true for Javascript).

 

I'd suggest you put an Alert(records[n]) in there somewhere just to make sure the Id field is always populated properly.  And at least for me, I don't like the idea of running multiple queries unless it's necessary. 

 

 

SELECT Account__c from Queued_account__c WHERE Id IN ('Id1', 'Id2')

 

I think javascript has a combine or implode command that should make doing the above easy.