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
rajsrajs 

How to handle the List in APEX

Hi All
    In my Components table having 2000 records. 1500  components are  Old  Components  and  500 are New.
my requirement is to display  all the 'Old Components'  in a picklist. when i use List like

List<Components__c> Equip=[select Id, Name, category__c from Components__c where category__c=:'old'];

to get the old components it shows error message.I think its Apex governor limit problem.how can i overcome this problem?

Regards
Raj
Guyver118Guyver118
Hi i am assuming  category is a picklist or some string value field so just do this

List<Components__c> Equip = [ SELECT  Id, Name, category__c FROM Components__c WHERE category__c = 'old' ];

you would use =: when assign it to a variable like

String token =  'old';

then 

List<Components__c> Equip = [ SELECT  Id, Name, category__c FROM Components__c WHERE category__c = :token];


Message Edited by Guyver118 on 01-19-2009 07:09 AM
rajsrajs

Thanks Guyver,

              Still it shows governor limit error. How can I handle the situations like thousands of records processing by list.

andresperezandresperez

Hi,

Split the records you are getting using another field, not only on category = 'old' and allow the user to select which records he wants to obtain.

 

I do not know your data so I can not make assumptions, but for example you could allow users to select the names by first letter, showinf only the ones that start with' A' or the ones that are from 'A' to 'G'.

Guyver118Guyver118
please paste the error message first and make sure that the list is not in a for loop or something, it should be declared once.
rajsrajs

Hi

 

I can't split a records because of my requirements.

 

   Error msg :

Inline query has too many rows for direct assignment, use FOR loop

An unexpected error has occurred. Your development organization has been notified.

 

sample code:

 

public class OldComponents { List<Components__c> Equip=new List<Components__c>(); public OldComponents() { Equip=[select Id, Name, category__c from Components__c where category__c='old'];//category__c is a Picklist } // so on .. }

 

 please give a idea to handle large records.

 

 

Thanks 

 

Guyver118Guyver118

try .................

 

 

 


public OldComponents()
{
for(List<Components__c> equip : [select Id, Name, category__c from Components__c where category__c='old'])
{
//do something with equip
}


}

 

 

 

 

 

Message Edited by Guyver118 on 01-21-2009 03:16 AM
andresperezandresperez

Hi,

Without trying to start an argument... are you going to present the user with a list of 1500 rows of data? Your page is going to look quite large.

A related idea to the one I gave you before, you could try this: 

 

List<Components__c> Equip=new List<Components__c>();
public OldComponents() {

List<Components__c> tmpEquip;

Equip = new List<Components__c>();


tmpEquip = [select Id, Name, category__c from Components__c where category__c='old' AND upper(mid(Name,1,1)) >= 'A' AND upper(mid(Name,1,1)) < 'P'];

Equip.addAll(tmpEquip);

tmpEquip = [select Id, Name, category__c from Components__c where category__c='old' AND upper(mid(Name,1,1)) >= 'P' AND upper(mid(Name,1,1)) <= 'Z'];

Equip.addAll(tmpEquip);

tmpEquip = [select Id, Name, category__c from Components__c where category__c='old' AND upper(mid(Name,1,1)) > 'Z' OR upper(id(Name,1,1)) < 'A']; //category__c is a Picklist

Equip.addAll(tmpEquip); // This will handle numbers and special characters...


}

 

 

andresperezandresperez

Hi,

 

I think rajs meant "recordsets" not "records"

rajsrajs

Hi

    Still I have a error like

   System.Exception: collection exceeds maximum size: 1500

 

List is not capable to hold more than 1000 records. Can you tell me if any other way? Or where I made mistake?

 

Thanks for your help

 

 

Guyver118Guyver118
try using @future
rajsrajs

Thanks Guyver,

     I am new to APEX so don't know the '@future' functions and how to use in APEX Class.

Please send me sample code for above example .I hope it will help me.