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
anurajanuraj 

limit

Hi

Please tell me what is the use of limit in qures.

 

Have written the code like this

 Timecard_Base__c timebase = new Timecard_Base__c();
      timebase  = [select WeekStartdate__c from Timecard_Base__c ];

 then i got error that

 

System.QueryException: List has more than 1 row for assignment to SObject 
Class.NigiController.retrive: line 10, column 19 External entry point

 

but when i changed code to

Timecard_Base__c timebase = new Timecard_Base__c();
      timebase  = [select WeekStartdate__c from Timecard_Base__c limit 1];

 i am only getting 1 value i want all the values. Please help me .

thanks

Anuraj

 

Best Answer chosen by Admin (Salesforce Developers) 
raseshtcsraseshtcs

The query in the first instance will return all the records from the object Timecard_Base__c. to store all the records you will need to have a list of the object type as follows

List<Timecard_Base__c> timebase = new  List<Timecard_Base__c>([select WeekStartdate__c from Timecard_Base__c]);

Now you can iterate through the list using a for loop etc.