You need to sign in to do that
Don't have an account?
Achtung
Iterate the items on the List of List created - Apex Trigger Code
So I created a List of List in my Apex Trigger code to list out all service IDs and the Job IDs associated with them. The structure looks like this:
The Service object contains the startDate and endDate fields. The Job object also has jobStart and jobEnd date fields.
What I intend to do is, if the dates of a Service record ID are updated, it will loop through all the jobs assigned to that service ID and check if there are dates that are not within the new date duration. This won't allow the user to update the Service record because jobs currently associated with it conflict with the new dates.
The Service object contains the startDate and endDate fields. The Job object also has jobStart and jobEnd date fields.
What I intend to do is, if the dates of a Service record ID are updated, it will loop through all the jobs assigned to that service ID and check if there are dates that are not within the new date duration. This won't allow the user to update the Service record because jobs currently associated with it conflict with the new dates.
All Answers
Will ther be another way to avoid the For Loop inside the For Loop?
Thanks.
There are no design principles that have been violated. This code will not hit any governor limits.
The inner for loop is executed once per each item in the outer loop.
I'm revising my logic in such a way that only Agreements where either their start date or end date is changed will be stored in the Trigger.new set.
And also, to make the SOQL more efficient, I only want to search for jobs where their agreement Id is found the set above and their job start or end date violates the new agreement start or end date.
Can you help revise your code for this? Thanks.