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
sfquestiondevsfquestiondev 

Limit in select

Hi, In MySQL we have limit on select for examle "SELECT * from Table where x=y order by z LIMIT 5,10"

 

It will return only 6,7,8,9 rows.

 

What is a equal sintax in appex trigger?

Starz26Starz26

Unfortunatly there is not a similar syntax.

 

You would have to put the LIMIT 10 in a SIQL, results to a list, then access hte list using array notation [6] [7] [8] [9] etc

SF Expert.ax1061SF Expert.ax1061

Hi,

 

Same syntax is not availabel in Apex..

You can do like this 

 

There is no * fro query you need to put manuaaly all teh fields like below

 

List<ObjectAPIName> lstOBj=[select  Id,Name from ObjectName limit 10];

 

//Now in lstOBj you have 10 records


//For 6th record

ObjectAPIName obj6thRecord=lstOBj[5];

 

//For 7th record

ObjectAPIName obj7thRecord=lstOBj[6];

 

//For 8th record

ObjectAPIName obj8thRecord=lstOBj[7];

 

//For 9th record

ObjectAPIName obj9thRecord=lstOBj[8];

 

//For 10th record

ObjectAPIName obj10thRecord=lstOBj[9];


 

//If you want all the record you can iterate in loop like below

for(ObjectApiName varObj:lstOBj){

sysytem.debug('varObj--------------->' + varObj);

}

 

Let me know if need any other help on this

 

Thanks

techie.in.sf@gmail.com

Navatar_DbSupNavatar_DbSup

Hi,
Use can do something like this:
List<account> acn=new list<account>();
for(account ac:[select id from account limit 10])
{ Integer i=1;
i++;
If(i>5 !! i<10)
{
acn.add(ac);
}

}
System.debug(‘@@@@@@@@@@@’ +acn);


And for working like * u have to make an string which will contain all the fields related to that object and pass that string as query using database.query method.

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.