You need to sign in to do that
Don't have an account?
Cris9931
How can I get rid of the error? As far As I saw the reason this error comes is because I have no results for that query...no?
how to solve: List has no rows for assignment to SObject?
Hi, on this line I have this error:
SVMXC__Timesheet_Entry__c relatedTimeEntry = [Select ID, SVMXC__Work_Detail__c from SVMXC__Timesheet_Entry__c where SVMXC__Work_Detail__c IN : workDetailIds limit 1];
trigger updateTimeEntriesHolidays on SVMXC__Service_Order_Line__c (after update) { //custom setting approach------------******* START Map<String, Holidays__mdt> holidays = Holidays__mdt.getAll(); Map<Date, Holidays__mdt> holidaysMap = new Map<Date,Holidays__mdt>(); Set<Id> workDetailIds = new Set<Id>(); for(SVMXC__Service_Order_Line__c newLines : Trigger.New) { if (newLines.SVMX_PS_Customer_Start_Date__c != Trigger.oldMap.get(newLines.Id).SVMX_PS_Customer_Start_Date__c) { workDetailIds.add(newLines.Id); } } for(Holidays__mdt ho: holidays.values()) { holidaysMap.put(ho.Holiday_Date__c, ho); } SVMXC__Timesheet_Entry__c relatedTimeEntry = [Select ID, SVMXC__Work_Detail__c from SVMXC__Timesheet_Entry__c where SVMXC__Work_Detail__c IN : workDetailIds limit 1]; List<SVMXC__Timesheet_Entry__c> TimeEntryToUpdate = new List<SVMXC__Timesheet_Entry__c>(); for(SVMXC__Service_Order_Line__c wl: Trigger.New) { Date workDetailStartDate = wl.SVMX_PS_Customer_Start_Date__c; if(holidaysMap.containsKey(workDetailStartDate )) { Date getDateHoliday = holidaysMap.get(workDetailStartDate).Holiday_Date__c; if(workDetailStartDate == getDateHoliday) { SVMXC__Timesheet_Entry__c newTimeEntry = new SVMXC__Timesheet_Entry__c(); newTimeEntry.Id = relatedTimeEntry.Id; newTimeEntry.isHoliday__c = TRUE; TimeEntryToUpdate.add(newTimeEntry); } } else { SVMXC__Timesheet_Entry__c newTimeEntry = new SVMXC__Timesheet_Entry__c(); newTimeEntry.Id = relatedTimeEntry.Id; newTimeEntry.isHoliday__c = False; TimeEntryToUpdate.add(newTimeEntry); } } update TimeEntryToUpdate ; System.debug('TimeEntryToUpdate'+ TimeEntryToUpdate); }
How can I get rid of the error? As far As I saw the reason this error comes is because I have no results for that query...no?
is SVMXC__Work_Detail__c is look up to SVMXC__Service_Order_Line__c?
Thanks!
Ho Abhinav,
Yes. It's a lookup.