+ Start a Discussion
Brendan LallyBrendan Lally 

Trying to use .remove method on a List (sobject) class

I'm happily using a List array for a custom object (Listings__c) in my extension controller and returns and displays happily on the front-end.

Using Lists.add( x); to add my custom record (x) entry's into the Lists array


At one stage (after I delete a record) I need 2 update my array and get rid of the (now) deleted assoc rec.


Using the following code - but getting an error = "Error: Compile Error: Method does not exist or incorrect signature: [SOBJECT:Listings__c].remove()"

..for (Integer i=0; i < Lists.size(); i++)
.....{ if (Lists[i].id = exist_L.id)
.........{ // zap that row from the lists array
.............System.debug(LoggingLevel.INFO,'zapped #'+i+' in Lists, key='+Lists[i].Name);
.............Lists[i].remove(); // P33 and P189 Apex Lang ref
.........}
.....}

Now I know that my sObject doesn't have a remove() method but the List array (Lists) should know it and process it for that position (i)

Lal
tmatthiesentmatthiesen
Change this:
Lists[i].remove();

To this:
Listings__c removed =  Lists.remove(i);

Per the docs:
http://www.salesforce.com/us/developer/docs/apexcode/index_CSH.htm#apex_methods_system_list.htm
Brendan LallyBrendan Lally
Thanks I'll try that. I managed 2do a workaround via a temp copy to another list array and then swap at the end.

Lal
Brendan LallyBrendan Lally
interesting.
Sf need 2 doc each of those with examples.

U would think that 'remove' contains something but nope its empty.

I had 2 backtrack from my workaround as had some 'side-effect'
I'd assign my recs ok to Lists, then copy only ones I wanted (not the one that got removed) to a 2nd array list2 via a loop.
That worked fine list2 = Lists; // swap them over -- good
however list2.clear (); // clear down list2 as have data in Lists again
would cause Lists to clear as well!!

Weird.

Lal