Skip to main content
Rollback to Revision 4
Source Link
David Reed
  • 93.7k
  • 14
  • 90
  • 166

I created a simple Apex Trigger that shows an error message when user tries to create an event without adding any attendee. I created a custom label for error message and its translations in different languages. This works fine in all the languages except for one (Japanese). The record gets saved if the user's language is Japanese.

trigger Event_Attendee_Validation on Event (after insert, after update) {
    Id ManagerRecordTypeId = Schema.SObjectType.Event.getRecordTypeInfosByName().get('Manager').getRecordTypeId();
    System.Debug('Event_Attendee_Validation Get RT ==> ' + ManagerRecordTypeId ); 
    try{
        for(Event event: Trigger.New){
            if (event.IsChild == false && event.Type == 'Dual Day' && event.RecordTypeId == ManagerRecordTypeId) {
                List<Event> childevents = [SELECT id From Event Where Task_Reference__c =:event.Task_Reference__c AND RecordTypeId =:event.RecordTypeId];
                System.Debug('Event_Attendee_Validation Get Child Events ==> ' + childevents );           
                if (childevents.size() == 1){
                    Trigger.New[0].addError(Label.Dual_Day_Attendee_Error);
                    }
                }        
            }
        }
    catch(Exception e){
        System.debug('Event_Attendee_Validation ==> Error found inside for loop');
    }
}

I created a simple Apex Trigger that shows an error message when user tries to create an event without adding any attendee. I created a custom label for error message and its translations in different languages. This works fine in all the languages except for one (Japanese). The record gets saved if the user's language is Japanese.

I created a simple Apex Trigger that shows an error message when user tries to create an event without adding any attendee. I created a custom label for error message and its translations in different languages. This works fine in all the languages except for one (Japanese). The record gets saved if the user's language is Japanese.

trigger Event_Attendee_Validation on Event (after insert, after update) {
    Id ManagerRecordTypeId = Schema.SObjectType.Event.getRecordTypeInfosByName().get('Manager').getRecordTypeId();
    System.Debug('Event_Attendee_Validation Get RT ==> ' + ManagerRecordTypeId ); 
    try{
        for(Event event: Trigger.New){
            if (event.IsChild == false && event.Type == 'Dual Day' && event.RecordTypeId == ManagerRecordTypeId) {
                List<Event> childevents = [SELECT id From Event Where Task_Reference__c =:event.Task_Reference__c AND RecordTypeId =:event.RecordTypeId];
                System.Debug('Event_Attendee_Validation Get Child Events ==> ' + childevents );           
                if (childevents.size() == 1){
                    Trigger.New[0].addError(Label.Dual_Day_Attendee_Error);
                    }
                }        
            }
        }
    catch(Exception e){
        System.debug('Event_Attendee_Validation ==> Error found inside for loop');
    }
}
deleted 1099 characters in body
Source Link

I created a simple Apex Trigger that shows an error message when user tries to create an event without adding any attendee. I created a custom label for error message and its translations in different languages. This works fine in all the languages except for one (Japanese). The record gets saved if the user's language is Japanese.

trigger Event_Attendee_Validation on Event (after insert, after update) {
    Id ManagerRecordTypeId = Schema.SObjectType.Event.getRecordTypeInfosByName().get('Manager').getRecordTypeId();
    System.Debug('Event_Attendee_Validation Get RT ==> ' + ManagerRecordTypeId ); 
    try{
        for(Event event: Trigger.New){
            if (event.IsChild == false && event.Type == 'Dual Day' && event.RecordTypeId == ManagerRecordTypeId) {
                List<Event> childevents = [SELECT id From Event Where Task_Reference__c =:event.Task_Reference__c AND RecordTypeId =:event.RecordTypeId];
                System.Debug('Event_Attendee_Validation Get Child Events ==> ' + childevents );           
                if (childevents.size() == 1){
                    Trigger.New[0].addError(Label.Dual_Day_Attendee_Error);
                    }
                }        
            }
        }
    catch(Exception e){
        System.debug('Event_Attendee_Validation ==> Error found inside for loop');
    }
}

I created a simple Apex Trigger that shows an error message when user tries to create an event without adding any attendee. I created a custom label for error message and its translations in different languages. This works fine in all the languages except for one (Japanese). The record gets saved if the user's language is Japanese.

trigger Event_Attendee_Validation on Event (after insert, after update) {
    Id ManagerRecordTypeId = Schema.SObjectType.Event.getRecordTypeInfosByName().get('Manager').getRecordTypeId();
    System.Debug('Event_Attendee_Validation Get RT ==> ' + ManagerRecordTypeId ); 
    try{
        for(Event event: Trigger.New){
            if (event.IsChild == false && event.Type == 'Dual Day' && event.RecordTypeId == ManagerRecordTypeId) {
                List<Event> childevents = [SELECT id From Event Where Task_Reference__c =:event.Task_Reference__c AND RecordTypeId =:event.RecordTypeId];
                System.Debug('Event_Attendee_Validation Get Child Events ==> ' + childevents );           
                if (childevents.size() == 1){
                    Trigger.New[0].addError(Label.Dual_Day_Attendee_Error);
                    }
                }        
            }
        }
    catch(Exception e){
        System.debug('Event_Attendee_Validation ==> Error found inside for loop');
    }
}

I created a simple Apex Trigger that shows an error message when user tries to create an event without adding any attendee. I created a custom label for error message and its translations in different languages. This works fine in all the languages except for one (Japanese). The record gets saved if the user's language is Japanese.

Code formatting
Source Link
Girbot
  • 5.6k
  • 2
  • 43
  • 62

I created a simple Apex Trigger that shows an error message when user tries to create an event without adding any attendee. I created a custom label for error message and its translations in different languages. This works fine in all the languages except for one (Japanese). The record gets saved if the user's language is Japanese.

trigger Event_Attendee_Validation on Event (after insert, after update) { Id ManagerRecordTypeId = Schema.SObjectType.Event.getRecordTypeInfosByName().get('Manager').getRecordTypeId(); System.Debug('Event_Attendee_Validation Get RT ==> ' + ManagerRecordTypeId ); try{ for(Event event: Trigger.New){ if (event.IsChild == false && event.Type == 'Dual Day' && event.RecordTypeId == ManagerRecordTypeId) { List childevents = [SELECT id From Event Where Task_Reference__c =:event.Task_Reference__c AND RecordTypeId =:event.RecordTypeId]; System.Debug('Event_Attendee_Validation Get Child Events ==> ' + childevents );
if (childevents.size() == 1){ Trigger.New[0].addError(Label.Dual_Day_Attendee_Error); } }
} } catch(Exception e){ System.debug('Event_Attendee_Validation ==> Error found inside for loop'); } }

trigger Event_Attendee_Validation on Event (after insert, after update) {
    Id ManagerRecordTypeId = Schema.SObjectType.Event.getRecordTypeInfosByName().get('Manager').getRecordTypeId();
    System.Debug('Event_Attendee_Validation Get RT ==> ' + ManagerRecordTypeId ); 
    try{
        for(Event event: Trigger.New){
            if (event.IsChild == false && event.Type == 'Dual Day' && event.RecordTypeId == ManagerRecordTypeId) {
                List<Event> childevents = [SELECT id From Event Where Task_Reference__c =:event.Task_Reference__c AND RecordTypeId =:event.RecordTypeId];
                System.Debug('Event_Attendee_Validation Get Child Events ==> ' + childevents );           
                if (childevents.size() == 1){
                    Trigger.New[0].addError(Label.Dual_Day_Attendee_Error);
                    }
                }        
            }
        }
    catch(Exception e){
        System.debug('Event_Attendee_Validation ==> Error found inside for loop');
    }
}

I created a simple Apex Trigger that shows an error message when user tries to create an event without adding any attendee. I created a custom label for error message and its translations in different languages. This works fine in all the languages except for one (Japanese). The record gets saved if the user's language is Japanese.

trigger Event_Attendee_Validation on Event (after insert, after update) { Id ManagerRecordTypeId = Schema.SObjectType.Event.getRecordTypeInfosByName().get('Manager').getRecordTypeId(); System.Debug('Event_Attendee_Validation Get RT ==> ' + ManagerRecordTypeId ); try{ for(Event event: Trigger.New){ if (event.IsChild == false && event.Type == 'Dual Day' && event.RecordTypeId == ManagerRecordTypeId) { List childevents = [SELECT id From Event Where Task_Reference__c =:event.Task_Reference__c AND RecordTypeId =:event.RecordTypeId]; System.Debug('Event_Attendee_Validation Get Child Events ==> ' + childevents );
if (childevents.size() == 1){ Trigger.New[0].addError(Label.Dual_Day_Attendee_Error); } }
} } catch(Exception e){ System.debug('Event_Attendee_Validation ==> Error found inside for loop'); } }

I created a simple Apex Trigger that shows an error message when user tries to create an event without adding any attendee. I created a custom label for error message and its translations in different languages. This works fine in all the languages except for one (Japanese). The record gets saved if the user's language is Japanese.

trigger Event_Attendee_Validation on Event (after insert, after update) {
    Id ManagerRecordTypeId = Schema.SObjectType.Event.getRecordTypeInfosByName().get('Manager').getRecordTypeId();
    System.Debug('Event_Attendee_Validation Get RT ==> ' + ManagerRecordTypeId ); 
    try{
        for(Event event: Trigger.New){
            if (event.IsChild == false && event.Type == 'Dual Day' && event.RecordTypeId == ManagerRecordTypeId) {
                List<Event> childevents = [SELECT id From Event Where Task_Reference__c =:event.Task_Reference__c AND RecordTypeId =:event.RecordTypeId];
                System.Debug('Event_Attendee_Validation Get Child Events ==> ' + childevents );           
                if (childevents.size() == 1){
                    Trigger.New[0].addError(Label.Dual_Day_Attendee_Error);
                    }
                }        
            }
        }
    catch(Exception e){
        System.debug('Event_Attendee_Validation ==> Error found inside for loop');
    }
}
included code
Source Link
Loading
added 59 characters in body
Source Link
Loading
Source Link
Loading