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
Bob.390672021994282E12Bob.390672021994282E12 

AddSelected Custom List Button

I wanted to create a list view button, that will update all of the status that the users selects on the list view screen. (Salesforce Declarative Screen. )

When running the custom button I am getting the below error. 

System.UnexpectedException: Cannot add() on a class java.util.Arrays$ArrayList
Error is in expression '{!SubmitAllRequests}' in component <apex:page> in page submitall: External entry point

Is there anyway to do this without using JavaScript? Or having the records on a screen. The end result will be that whatever the user selects if conditions are met on the records will update the records accordingly. I am assuming based on the error that Salesforce doesnt allow add to their array class. Anythoughts on how to get around this? 




public with sharing class SubmitAllButton{

    Id CurrentUserID = UserInfo.GetUserID();
     
    set<id> UserSelect= new set<id>();
    
    private ApexPages.StandardSetController standardController;

    public SubmitAllButton(ApexPages.StandardSetController standardController)
    {
        this.standardController = standardController;
    }
     
    public PageReference SubmitAllRequests() {
 
       List<Object__c> Newrecordss= (List<Object__c>) standardController.getSelected();
       
       for(Object__c newrecords: Newrecordss)
        {
            UserStartDates.add(newrecords.id);
            system.debug('UserStartDates' + UserStartDates);
        }   
           
           
         for (Object__c UnSubmittedRequests: [SELECT Id, Next_Step__c, CreatedById, Attachement__c   FROM Object__c WHERE id=: UserSelect
         and CreatedById =: CurrentUserID  ])
             {
                
             
                if (UnSubmittedRequests.Next_Step__c == null && UnSubmittedRequests.Attachement__c != True){
                
                system.debug('UnSubmittedRequests' + UnSubmittedRequests);
                
                Object__c NewRecords = new Object__c ();
                
                
                NewRecords.id = UnSubmittedRequests.id;
                NewRecords.Next_Step__c = 'Request Review';
        
                 Newrecordss.add(NewRecords);   // this is where the error occurs. 
                  
                 
                }
                
                }
                
                
           
               update Newrecordss;
             
                
                return redirectToList();
                 
             }
             
            public PageReference redirectToList()  {
            Schema.DescribeSObjectResult result = ADR__c.SObjectType.getDescribe();
            PageReference pageRef = new PageReference('/' + result.getKeyPrefix());
            pageRef.setRedirect(true);
            return pageRef;
            
            }
            
             }




The page isnt doing anything except call the method to update

<apex:page standardController="Object__c" extensions="SubmitAllButton" recordSetVar="selected" action="{!SubmitAllRequests}">

</apex:page>
Best Answer chosen by Bob.390672021994282E12
Bob.390672021994282E12Bob.390672021994282E12
opps, I see. 

In case someone is wondering how this can be done. Add the below

list<object__c> Results = new list <object__c>();


 Results.add(NewRecords);  
}

update Results