I have a before trigger to compare dates on entry. I want to get a recond based on an id from a map, How do I achieve this. Below is my example with my question on line
AAddress__c dummy = AccountAddress.get(aAN.id);
Apex
public void OnBeforeInsert(List<AAddress__c> newAccountAddress){
//EXECUTE BEFORE INSERT LOGIC
date dateFilter = date.today().AddDays(- 5);
Map<ID, AAddress__c> AccountAddress = new Map<ID, AAddress__c>([SELECT Id, Start_Date__c, End_Date__c, Account__c, Address_Type__c FROM AAddress__c WHERE Start_Date__c <= TODAY AND End_Date__c >= TODAY AND Status__c = true AND (LastModifiedDate >= :dateFilter OR LastModifiedDate = null)]);
system.debug('AccountAddress: '+AccountAddress);
for (AAddress__c aAN : newAccountAddress){
AAddress__c dummy = AccountAddress.get(aAN.account__c);
system.debug('dummy: '+dummy);
if(aAN.Start_Date__c>= dummy.Start_Date__c && aAN.Start_Date__c <= dummy.End_Date__c ){
aAN.addError('This startdate interferes with another adress');
}
if(aAN.End_Date__c>= dummy.Start_Date__c && aAN.End_Date__c <= dummy.End_Date__c ){
aAN.addError( 'This enddate interferes with another adress');
}
}
}