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
p100p100 

List has more than 1 row for assignment to sobject

Hi

 

In my trigger im getting the above error when assigning the results of the query to the List. Works fine on individual records but not when updating bulk data. Any ideas where im going wrong? Code below:

 

    if(Trigger.isBefore) 
    {
        if(Trigger.isUpdate)
        {
            string fy;
            system.debug('After UPDATE');  
            
            List<JS_Calendar__c> fyInfo = new List<JS_Calendar__c>();
            fyInfo = [Select Date__c, Financial_Year__c, Quarter__c, Period__c, Week__c 
                                            From JS_Calendar__c 
                                            Where Date__c =:[Select Launch_Date__c 
                                                            from InvestmentProgram__c 
                                                            where Id in: Trigger.newmap.keyset()].Launch_Date__c];
                                                            

 thanks

Best Answer chosen by Admin (Salesforce Developers) 
Naidu PothiniNaidu Pothini
List<Date> dateList = new List<Date>();

for(InvestmentProgram__c dt : [SELECT Launch_Date__c FROM InvestmentProgram__c WHERE Id IN :Trigger.newmap.keyset()])
{
	dateList.add(dt.Launch_Date__c);
}

fyInfo = [SELECT Date__c, Financial_Year__c, Quarter__c, Period__c, Week__c 
          FROM JS_Calendar__c 
          WHERE Date__c IN :dateList];

 Try this.

 

 

All Answers

Naidu PothiniNaidu Pothini
List<Date> dateList = new List<Date>();

for(InvestmentProgram__c dt : [SELECT Launch_Date__c FROM InvestmentProgram__c WHERE Id IN :Trigger.newmap.keyset()])
{
	dateList.add(dt.Launch_Date__c);
}

fyInfo = [SELECT Date__c, Financial_Year__c, Quarter__c, Period__c, Week__c 
          FROM JS_Calendar__c 
          WHERE Date__c IN :dateList];

 Try this.

 

 

This was selected as the best answer
Vinit_KumarVinit_Kumar

Your code is not optimized ti handle bulk request.If you can make your requirement clear,then can help you out.