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

Why This is not possible


List<Account> accounts =  [Select Id, Name, (Select Id, Name From Contacts) From Account ]


for(Account a : accounts){
for(Integer i=0; i < a.Contacts.size() ; i++){
if(someCondition){ a.Contacts.remove(i);
} } }

 This should idealy remove contacts where condition is satisfied


But it dose not happen




You are not performing any of the DML process in the above code,


So perform some and then check the results, just by removing from the list records are not going to be deleted


Thanks Abhi,

But my expected output is not to delete but just not to display in the frontend.

one way to achive is through wrapper classes. but the question stands still the same 

Contacts is Wrapper Classes. but the Question is 


a.Contacts is a list Object;

for eg : list<Contact> cons = a.contacts;

What is possible


what is not possible





Rahul AgarwalRahul Agarwal

Say there are three elements in a list and second element satisfies the if condition. Then you are trying to remove the second element from the list while you are pointing at the same element in the list.