You need to sign in to do that
Don't have an account?
lovetolearn
Problem with SOQL Query
Hi,
I am trying to create a trigger that creates junction object record only if it finds records in the query that i specified. For some reason the parameters that I specify in my query does not seem to be working right. Here is my code:
trigger testCreateHoliday on Leave_Request__c (after insert) { Leave_Request__c insertLR = new Leave_Request__c(); Date startDate = insertLR.Request_Start_Date__c; Date endDate = insertLR.Request_End_Date__c; Decimal testnum = insertLR.testnum__c; List<Holiday__c> allHoliday=[SELECT ID FROM Holiday__c Where Holiday_Start_Date__c >: startDate AND Holiday_Start_Date__c <: endDate ORDER BY Holiday_Start_Date__c DESC]; insertLR = trigger.new[0]; Integer x = allHoliday.size(); List<LR_and_Holiday__c> lrholidaylist = new List<LR_and_Holiday__c>(); if(x > 0){ for (Integer i = 1; i<=x; i++){ LR_and_Holiday__c lrholiday = new LR_and_Holiday__c(); lrholiday.Leave_Request__c = insertLR.ID; lrholiday.Holiday__c = allholiday[(x-1)].ID; lrholidaylist.add(lrholiday); x--; } Database.insert(lrholidaylist); } }
I think it may be the way that I instaniated the Leave_Request object.
Please help.
Thank you.
Please do the system debug for
Date startDate = insertLR.Request_Start_Date__c;
Date endDate = insertLR.Request_End_Date__c;
I think You are not getting anything in this ..
Ah all good. I fixed it. There was a problem with the way I was instaniating the Leave Request object.
Thanks for your help.