• Dharani Mohan 5
  • NEWBIE
  • 10 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 1
    Replies
Challenge Not yet complete... here's what's wrong: 
The trigger logic failed to prevent double booking of a speaker. Please double check the 'RejectDoubleBooking' trigger code.
Here  is my code:

trigger RejectDoubleBooking on Session_Speaker__c (before insert,Before update) {
    List<Id> SpeakerIds= new List<Id>();
    Map<Id,DateTime> req_bookings = new  Map<Id,DateTime>();
    For(Session_Speaker__c newItem :Trigger.New )
    {
        SpeakerIds.add(newItem.Speaker__c);
        req_bookings.put(newItem.Session__c,null);
    }
    
    List<Session__c> requested_sessions = [SELECT Id, Session_Date__c
                                                   from Session__c WHERE ID IN :req_bookings.keySet()];
    For(Session__c  s:requested_sessions )
    {
       req_bookings.put(s.Id, s.Session_Date__c); 
    }
    system.debug(requested_sessions);
    List<Session_Speaker__c> relatedSpeakers=[Select Id,Session__c,Speaker__c,Session__r.Session_Date__c
                                            FROM Session_Speaker__c where Speaker__c  in :SpeakerIds];
    
    For(Session_Speaker__c reqSession : Trigger.New)
    {
        datetime booktime= req_bookings.get(reqSession.Session__c);
        For(Session_Speaker__c relSpeaker: relatedSpeakers)
        {
           if(reqSession.speaker__c==relSpeaker.Speaker__c && booktime==relSpeaker.Session__r.Session_Date__c )
           {
               reqSession.addError('The speaker is already booked at that time');
           }
            
        }
    }

}

It shows the msg 'The speaker is already booked at that time'  in execute anonymous window.. but it save the value..
Can anyone help me to complete this?

 
I already did in previous version.. In new version Can any one help to complete checkchallenge Data Security-> Control Access to Fields?
I already did in previous version.. In new version Can any one help to complete checkchallenge Data Security-> Control Access to Fields?