You need to sign in to do that
Don't have an account?
Ab
Change record type of events based on record types of contact
Hello,
I have below code which changes the record type of "Event" based on record type "Account",
How can i modify it to have it for record type of contacts. I want change the record type of event if it belongs to record types C1, C2, C3.
Id a1 = Schema.SObjectType.Account.getRecordTypeInfosByName().get('X').getRecordTypeId();
It gives me error for below line when i try for Contact
I have below code which changes the record type of "Event" based on record type "Account",
How can i modify it to have it for record type of contacts. I want change the record type of event if it belongs to record types C1, C2, C3.
Id a1 = Schema.SObjectType.Account.getRecordTypeInfosByName().get('X').getRecordTypeId();
Id e1 = Schema.SObjectType.Event.getRecordTypeInfosByName().get('Y').getRecordTypeId(); Id e2 = Schema.SObjectType.Event.getRecordTypeInfosByName().get('Z').getRecordTypeId(); List<Event> eventList = [Select AccountId,RecordTypeId from Event where AccountId != null and RecordTypeId=:e1]; Set<Id> accIds = new Set<Id>(); for(Event evt : eventList){ accIds.add(evt.AccountId); } Map<Id,Account> accMap = new Map<id,account>([Select RecordTypeId from Account]); integer count = 0; for(Event evt : eventList){ if(accMap.containsKey(evt.AccountId)){ if(accMap.get(evt.AccountId).RecordTypeId == a1){ evt.RecordTypeId = e2; count++; } } } update eventList;
It gives me error for below line when i try for Contact
List<Event> eventList = [Select ContactId,RecordTypeId from Event where ContactId != null];
All Answers
try to modifiy like this....
Event has AccountId relationship with Account ,how ever it is related to contact with WhoId .So you need to relace contactid with WhoId ,To know more detail about relationship with event with other objects please check with below link .
https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_erd_activities (https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_erd_activities.htm)