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
madhava ramana 7madhava ramana 7 

I am trying to retrive value from more than 2000 records, so in the process, i want to fetch the id value of 2000th record and assign it to a variable.Please let me know the syntax.

I am trying to retrive value from more than 2000 records, so in the process i want to fetch the id value of 2000th record and assign it to a variable.Please let me know the syntax.
Justin CastileJustin Castile
For a trigger on an object, from the object's management settings, go to Triggers, click New, and then enter your code in the Body text box. For a class, from Setup, enter Apex Classes in the Quick Find box, mysubwaycard (https://www.mysubwaycard.pro/), then select Apex Classes. Click New, and then enter your code in the Body text box.
{tushar-sharma}{tushar-sharma}
As you are storing the data in a list, So just get the 1999 index variable
reordList[1999];//it will return you 2000 element

If this answer helps you, please mark it as accepted.

Regards,
Tushar Sharma
https://newstechnologystuff.com/
Philippe UyttendaelePhilippe Uyttendaele
Hello madhava,

you may want to elaborate on what exactly you want to achieve when you say 'fetch the id value of the 2000th element.

From experience you are probably updating many records and, as gouvernor limits hits at 2000, you need to pass where you stopped.

If you want to do mass update, you would be better off with automated process to do the handling of where you left it off.
The Batchable class can help you manage the indexing of the different blocks this way you actually don't need to worry about where you left the process.
here is an example of code that does the trick for mass update of ALL contact emails and add a .test at the end (we use it in our sandboxes to avoid sending emails to contact)

I'd be happy to further help you if you give more information about what you are truely trying to achieve.

best
 
global class BatRenameEmailAddresses implements Database.Batchable<sObject>{

    global void execute(Database.BatchableContext bc, List<Contact> scope) {
        List<Contact> contactsTuUpdate=new List<Contact>();

        for (Contact c : scope) {
            Boolean contactToAdd=false;
            if(c.Email!=null && !c.Email.contains('test')){
                c.Email=c.Email+'.test';
                contactToAdd=true;
            }
            if(contactToAdd){
                contactsTuUpdate.add(c);
            }

        }
        update contactsTuUpdate;
    }

    global void finish(Database.BatchableContext bc) {

    }

    global  Database.QueryLocator start(Database.BatchableContext bc) {
        String soql='SELECT Id,Email From Contact ';
        return Database.getQueryLocator(soql);
    }

}