You need to sign in to do that
Don't have an account?
bikla78
Else if statement never hits
The highlighted statement below never executes when the event.whatid is associated with an account record where account.dlc_territory = San Francisco.
Everything else works. Any help will be greatly appreciated
public static void EventAssign (Event[] EventRec)
{
Set<Id> acctIds = new Set<Id>();
for (Event ev : EventRec)
{
acctIds.add(ev.whatId);
}
Map<Id,String> EventAssignMap = new Map<Id, String>();
for(Account acct: [select id, ownerid from Account where dlc_territory__c != 'San Francisco' and id IN :acctIds])
{
EventAssignMap .put(acct.id, acct.ownerid);
for (Event a:EventRec)
{
if( a.whatid != EventAssignMap.get(acct.id))
{
if (a.meeting_status__c== 'Pending' || a.meeting_status__c== 'Executed')
{
a.ownerid = EventAssignMap .get(a.whatId);
}
}
else if (a.ownerid !='00530000000eQr3AAE' || a.ownerid != '00530000000cvXwAAI')
{
a.ownerid.adderror ('Test');
}
}
}
}
your map contains ownerIds as its values, the whatId of an event will never be an owner id, therefore the if != check is always true.
you also appear to be checking all the events for all the accounts, perhaps you're missing a } after the EventAssignMap.put line? (i.e. populate the map, then check the events?)
Firstly, are you sure the records are not own by these owners?
If you are, try to check the "OwnerId" field in your EventRec array, is it a 15 characters Id or 18 characters Id?