• Andrew Hoban 14
  • NEWBIE
  • 30 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 9
    Questions
  • 12
    Replies
Hi all,

I am creating a trgger that will fire an error when a particular picklist value has been selected three times. This works and the error message displays.

I now need the error to display if a date from a  date field has been selected three times.

I am unsure how i would implement this inside my trigger.
Any help would be appreciated. Thanks.

Trigger:
trigger SevenAsideQuantityTrigger on Opportunity (before insert,before update) {

Integer count =[select count() from Opportunity WHERE Select_Area__c='7-a-side Pitch' AND Start_Time__c!=null];
for(Opportunity a:trigger.new){
if(count==2&&a.Select_Area__c=='7-a-side Pitch'&& a.Start_Time__c=='09:00'){
a.addError('7-a-side Pitch is fully booked at this time.');
}
if(count==2&&a.Select_Area__c=='7-a-side Pitch'&& a.Start_Time__c=='10:00'){
a.addError('7-a-side Pitch is fully booked at this time.');
}
if(count==2&&a.Select_Area__c=='7-a-side Pitch'&& a.Start_Time__c=='11:00'){
a.addError('7-a-side Pitch is fully booked at this time.');
}
if(count==2&&a.Select_Area__c=='7-a-side Pitch'&& a.Start_Time__c=='12:00'){
a.addError('7-a-side Pitch is fully booked at this time.');
}
}
}

 
Hi all, 
I am having truble creating a test class for this particular class. If anyone could provide some code that would implement this I would be very grateful.

Many thanks

Class:
global class TalentIntCustomerBatch implements Database.Batchable<sObject>, Database.AllowsCallouts{
  global final String query;

  global TalentIntCustomerBatch(String q){
    query=q;
  }
  
  global Database.QueryLocator start(Database.BatchableContext BC){
    return Database.getQueryLocator(query);
  }

  global void execute(Database.BatchableContext BC, List<sObject> scope){    
    for(sObject s : scope){
      Contact c = (Contact)s;
      TalentIntegrationUtils.updateCustomer(c.Id, c.LastName);
    }
  }
  
  global void finish(Database.BatchableContext BC){}
}

 
Hi all,

Another develoer has created a trigger that is currently on 77% code coverage. I am trying to locate the test class to try and boost the trigger upto 100% however I am unable to locate it. is there a way to see the relationship between the trigger and the class? 

Thanks
Hi all,
I have a visualforce page that works great, however i need to implement a quick save button for users to quickly save the fields without having to refresh the page. I have used the standard quick save command button "<apex:commandButton value="Quick Save" action="{!QuickSave}"/>" however when the button is clicked the records are not saved. I have created a custom controller so im not sure if I need to reference the button inside it.

Many thanks

Controller:
public class IncidentLogPopup
{ 

 public List<Incident_Log__c> memberList {get;set;}
    public List<Incident_Log__c> memberAddList {get;set;}
    public String memberName {get;set;} 
    public string searchstring {get;set;} 

    
    public PageReference cancel() {
        return null;
    }


    public IncidentLogPopup() {

    }
    
   
    public IncidentLogPopup(ApexPages.StandardController controller) {
        String sql = 'SELECT Match_Day_Ops__c, Date_Time__c, Date_Closed__c, Type__c, Priority__c, Incident__c, Reported_to__c, Reported_By__c, Opened_Closed_Status__c FROM Incident_Log__c';
        memberList = Database.Query(sql);
        memberAddList = new List<Incident_Log__c>();
        memberAddList.add(new Incident_Log__c(Match_Day_Ops__c = 'a0Gf000000111CV', Date_Time__c = DateTime.Now()));
         
        
    }
    
    public void AddRow()
    {
        memberAddList.add(new Incident_Log__c(Match_Day_Ops__c = 'a0Gf000000111CV', Date_Time__c = DateTime.Now()));
        
    } 
    
    Public Pagereference Save(){
        insert memberAddlist;
        PageReference page = new Pagereference('/a0G/o');
                     page.setRedirect(true);
            return page;
  }
   
    
     

  


        
   }

VF Page:
<apex:page sidebar="false" StandardController="Match_Day_Ops__c"  extensions="IncidentLogPopup">

<style type = "text/css">
        .colHeadr {text-align:center;}     
    </style>

    
 


  <apex:form >
  
  
  

    <apex:pageBlock title="Incident Log {!$ObjectType.Match_Day_Ops__c.Fields.Name.Label}" id="membAdd" >  
    <apex:pageBlockButtons location="Both">
                <apex:commandButton value="Save" Action="{!save}" />
                <apex:commandButton value="Quick Save" action="{!QuickSave}"/> 
                <apex:commandButton value="Cancel" action="{!cancel}"/>
                </apex:pageBlockButtons>  
                
                
              
                                  
       <apex:pageblockSection >     
          
   
            <apex:pageBlockTable style="width:100%" value="{!memberAddList}" var="memb">     
                <apex:column headerValue="Match Day Ops" headerClass="colHeadr">
                    <apex:inputField value="{!memb.Match_Day_Ops__c}" style="width:325px" />
                </apex:column>
                <apex:column headerValue="Type" headerClass="colHeadr">
                    <apex:inputField value="{!memb.Type__c}"/>
                </apex:column>
                 <apex:column headerValue="Priority" headerClass="colHeadr">
                    <apex:inputField value="{!memb.Priority__c}"/>
                </apex:column>
                  <apex:column headerValue="Date/Time Opened" headerClass="colHeadr">
                    <apex:inputField value="{!memb.Date_Time__c}"/>
                </apex:column>
                <apex:column headerValue="Incident Open" headerClass="colHeadr">
                    <apex:inputField value="{!memb.Incident__c}" style="width: 200px; height: 80px"/>
                </apex:column>

             <apex:column headerValue="Date/Time Closed" headerClass="colHeadr">
                    <apex:inputField value="{!memb.Date_Closed__c}"/>
                </apex:column> 
                <apex:column headerValue="Incident Closed" headerClass="colHeadr">
                    <apex:inputField value="{!memb.Incident_Closed__c}" style="width: 200px; height: 80px"/>
                </apex:column>
                <apex:column headerValue="Reported To" headerClass="colHeadr">
                    <apex:inputField value="{!memb.Reported_To__c}"/>
                </apex:column>
                <apex:column headerValue="Reported By" headerClass="colHeadr">
                    <apex:inputField value="{!memb.Reported_By__c}"/>
                </apex:column>  
                
                </apex:pageBlockTable> 

        </apex:pageblockSection>    
           
        <apex:pageblockSection columns="1" >
            <apex:pageblockSectionItem >
<apex:commandLink value="Add Row" action="{!addRow}" reRender="membAdd" />  
           
            </apex:pageblockSectionItem>        
        </apex:pageblockSection>
    </apex:pageBlock>
</apex:form>

</apex:page>

 
Hi, 

I have a test class that has a compile error when I try to save. I was wondering if anybody could help.
Many thanks

Class:
public class MatchReadyImage {

public Match_Day_Check_List__c obj {get; set; }


public MatchReadyImage(){
           obj = [Select Id, Match_Day_Ready_Status__c  From Match_Day_Check_List__c Where Name = 'Everton V West Ham United Goodison Park EPL 2013-05-12'];
    }
}

Test Class:
@isTest(seeAllData = true)
private class MatchReadyImageTest {

    private static void MatchReadyImage() {
        Match_Day_Check_List__c mdckl = new Match_Day_Check_List__c(
            name = 'Everton V West Ham United Goodison Park EPL 2013-05-12',
             Fixture__c = [select id from CS_Fixture__c limit 1].id,
             Match_Plan__c = [select id from Pre_Match__c limit 1].id);

        insert mdckl;       
      
        System.assert((new MatchReadyImage).obj != null);
    }

}

 
Hi all, I was wondering if you could help me create a test class for the clontroller seen below. Any help would be appreciated,

Many thanks.
 
public class IncidentLogPopup
{ 

 public List<Incident_Log__c> memberList {get;set;}
    public List<Incident_Log__c> memberAddList {get;set;}
    public String memberName {get;set;} 
    public string searchstring {get;set;} 

    
    public PageReference cancel() {
        return null;
    }


    public IncidentLogPopup() {

    }
    
   
    public IncidentLogPopup(ApexPages.StandardController controller) {
        String sql = 'SELECT Match_Day_Ops__c, Date_Time__c, Date_Closed__c, Type__c, Priority__c, Incident__c, Reported_to__c, Reported_By__c, Opened_Closed_Status__c FROM Incident_Log__c';
        memberList = Database.Query(sql);
        memberAddList = new List<Incident_Log__c>();
        memberAddList.add(new Incident_Log__c(Match_Day_Ops__c = 'a0Gf000000111CV', Date_Time__c = DateTime.Now()));
         
        
    }
    
    public void AddRow()
    {
        memberAddList.add(new Incident_Log__c(Match_Day_Ops__c = 'a0Gf000000111CV', Date_Time__c = DateTime.Now()));
        
    } 
    
    Public Pagereference Save(){
        insert memberAddlist;
        PageReference page = new Pagereference('/a0G/o');
                     page.setRedirect(true);
            return page;
  }
   

        
   }

 
Hi,

I was wondering if its possible to update the quantity sold field when certain criteria is met. I have created one and for some reason it does not seem to trigger. I have attached an image of the workflow i have created. When a product is added to the opportunity i want the quantity to availibility to decrement by 1.

Many thanksUser-added imageUser-added image
Hi,

I was wondering if its possible to decrese the quantity of a product when it has been added from an opportunity.

For example, I have added 'Bowling Green' to a pricebook with an availibility of 3. So if one gets added to when an opportunity is created I would like the availibility tp then be 2. However at the moment the availibility remains the same no matter how many i add to an opportunity.

I am trying to create a booking/reservation system.

Many thanks
Andrew Hoban 
Hi,

I am currently in the process of creating a booking system. It should allow people to choose a specific area (Tennis Court) and time (9:00am) from two different picklists. However now that that area has been booked, there needs to be a way of not letting that area be availible for selection untill the time has passed. I have tried performing this with a trigger, however it does not allow the pricebook to be selected, nor does it let a lead conversion take place. I am unsure weather this can be done through workflows and validation rules. The code to my trigger is as follows:

trigger TriggerToValidateTennisCourt on opportunity (BEFORE INSERT, BEFORE UPDATE)
    {
        LIST<opportunity> li = [SELECT area_to_book__c, Start_Time__c FROM opportunity WHERE area_to_book__c = 'Bowling Green'];
        for(opportunity o :trigger.new)
        {
         if(o.area_to_book__c == 'Tennis Court' && o.Start_Time__c == '09:00' || o.Start_Time__c == '10:00'|| o.Start_Time__c == '11:00'|| o.Start_Time__c == '12:00'|| o.Start_Time__c == '13:00'|| o.Start_Time__c == '14:00'|| o.Start_Time__c == '15:00'|| o.Start_Time__c == '16:00'|| o.Start_Time__c == '17:00'|| o.Start_Time__c == '18:00'|| o.Start_Time__c == '19:00'|| o.Start_Time__c == '20:00')
         {
          for(opportunity existrecord :li)
          {
              if(existrecord.area_to_book__c == o.area_to_book__c){
              o.area_to_book__c.adderror('This area is fully booked. Please select another time.');
              }
              else if(o.area_to_book__c == 'Bowling Green' && o.Start_Time__c == '09:00' || o.Start_Time__c == '10:00'|| o.Start_Time__c == '11:00'|| o.Start_Time__c == '12:00'|| o.Start_Time__c == '13:00'|| o.Start_Time__c == '14:00'|| o.Start_Time__c == '15:00'|| o.Start_Time__c == '16:00'|| o.Start_Time__c == '17:00'|| o.Start_Time__c == '18:00'|| o.Start_Time__c == '19:00'|| o.Start_Time__c == '20:00')
              {
          for(opportunity existrecordBG :li)
          {
             if(existrecordBG.area_to_book__c == o.area_to_book__c){
              o.area_to_book__c.adderror('This area is fully booked. Please select another time.');
              }
          }
         }
        }

    }
    }
    }

Many thanks
Hi all,

I am creating a trgger that will fire an error when a particular picklist value has been selected three times. This works and the error message displays.

I now need the error to display if a date from a  date field has been selected three times.

I am unsure how i would implement this inside my trigger.
Any help would be appreciated. Thanks.

Trigger:
trigger SevenAsideQuantityTrigger on Opportunity (before insert,before update) {

Integer count =[select count() from Opportunity WHERE Select_Area__c='7-a-side Pitch' AND Start_Time__c!=null];
for(Opportunity a:trigger.new){
if(count==2&&a.Select_Area__c=='7-a-side Pitch'&& a.Start_Time__c=='09:00'){
a.addError('7-a-side Pitch is fully booked at this time.');
}
if(count==2&&a.Select_Area__c=='7-a-side Pitch'&& a.Start_Time__c=='10:00'){
a.addError('7-a-side Pitch is fully booked at this time.');
}
if(count==2&&a.Select_Area__c=='7-a-side Pitch'&& a.Start_Time__c=='11:00'){
a.addError('7-a-side Pitch is fully booked at this time.');
}
if(count==2&&a.Select_Area__c=='7-a-side Pitch'&& a.Start_Time__c=='12:00'){
a.addError('7-a-side Pitch is fully booked at this time.');
}
}
}

 
Hi all,

I am creating a trgger that will fire an error when a particular picklist value has been selected three times. This works and the error message displays.

I now need the error to display if a date from a  date field has been selected three times.

I am unsure how i would implement this inside my trigger.
Any help would be appreciated. Thanks.

Trigger:
trigger FiveAsideQuantityTrigger on Opportunity (before insert,before update) {

Integer count =[select count() from Opportunity WHERE Select_Area__c='5-a-side Pitch' AND Start_Time__c!=null];
for(Opportunity a:trigger.new){
if(count==3&&a.Area_Of_Hire__c=='5-a-side Pitch'&& a.Start_Time__c=='09:00'){
a.addError('5-a-side Pitch is fully booked at this time.');
}
if(count==3&&a.Area_Of_Hire__c=='5-a-side Pitch'&& a.Start_Time__c=='10:00'){
a.addError('5-a-side Pitch is fully booked at this time.');
}
if(count==3&&a.Area_Of_Hire__c=='5-a-side Pitch'&& a.Start_Time__c=='11:00'){
a.addError('5-a-side Pitch is fully booked at this time.');
}
if(count==3&&a.Area_Of_Hire__c=='5-a-side Pitch'&& a.Start_Time__c=='12:00'){
a.addError('5-a-side Pitch is fully booked at this time.');
}
if(count==3&&a.Area_Of_Hire__c=='5-a-side Pitch'&& a.Start_Time__c=='13:00'){
a.addError('5-a-side Pitch is fully booked at this time.');
}
if(count==3&&a.Area_Of_Hire__c=='5-a-side Pitch'&& a.Start_Time__c=='14:00'){
a.addError('5-a-side Pitch is fully booked at this time.');
}
if(count==3&&a.Area_Of_Hire__c=='5-a-side Pitch'&& a.Start_Time__c=='15:00'){
a.addError('5-a-side Pitch is fully booked at this time.');
}
if(count==3&&a.Area_Of_Hire__c=='5-a-side Pitch'&& a.Start_Time__c=='16:00'){
a.addError('5-a-side Pitch is fully booked at this time.');
}
if(count==3&&a.Area_Of_Hire__c=='5-a-side Pitch'&& a.Start_Time__c=='17:00'){
a.addError('5-a-side Pitch is fully booked at this time.');
}
if(count==3&&a.Area_Of_Hire__c=='5-a-side Pitch'&& a.Start_Time__c=='18:00'){
a.addError('5-a-side Pitch is fully booked at this time.');
}
if(count==3&&a.Area_Of_Hire__c=='5-a-side Pitch'&& a.Start_Time__c=='19:00'){
a.addError('5-a-side Pitch is fully booked at this time.');
}
if(count==3&&a.Area_Of_Hire__c=='5-a-side Pitch'&& a.Start_Time__c=='20:00'){
a.addError('5-a-side Pitch is fully booked at this time.');
}
}
}

 
Hi all,
I have a visualforce page that works great, however i need to implement a quick save button for users to quickly save the fields without having to refresh the page. I have used the standard quick save command button "<apex:commandButton value="Quick Save" action="{!QuickSave}"/>" however when the button is clicked the records are not saved. I have created a custom controller so im not sure if I need to reference the button inside it.

Many thanks

Controller:
public class IncidentLogPopup
{ 

 public List<Incident_Log__c> memberList {get;set;}
    public List<Incident_Log__c> memberAddList {get;set;}
    public String memberName {get;set;} 
    public string searchstring {get;set;} 

    
    public PageReference cancel() {
        return null;
    }


    public IncidentLogPopup() {

    }
    
   
    public IncidentLogPopup(ApexPages.StandardController controller) {
        String sql = 'SELECT Match_Day_Ops__c, Date_Time__c, Date_Closed__c, Type__c, Priority__c, Incident__c, Reported_to__c, Reported_By__c, Opened_Closed_Status__c FROM Incident_Log__c';
        memberList = Database.Query(sql);
        memberAddList = new List<Incident_Log__c>();
        memberAddList.add(new Incident_Log__c(Match_Day_Ops__c = 'a0Gf000000111CV', Date_Time__c = DateTime.Now()));
         
        
    }
    
    public void AddRow()
    {
        memberAddList.add(new Incident_Log__c(Match_Day_Ops__c = 'a0Gf000000111CV', Date_Time__c = DateTime.Now()));
        
    } 
    
    Public Pagereference Save(){
        insert memberAddlist;
        PageReference page = new Pagereference('/a0G/o');
                     page.setRedirect(true);
            return page;
  }
   
    
     

  


        
   }

VF Page:
<apex:page sidebar="false" StandardController="Match_Day_Ops__c"  extensions="IncidentLogPopup">

<style type = "text/css">
        .colHeadr {text-align:center;}     
    </style>

    
 


  <apex:form >
  
  
  

    <apex:pageBlock title="Incident Log {!$ObjectType.Match_Day_Ops__c.Fields.Name.Label}" id="membAdd" >  
    <apex:pageBlockButtons location="Both">
                <apex:commandButton value="Save" Action="{!save}" />
                <apex:commandButton value="Quick Save" action="{!QuickSave}"/> 
                <apex:commandButton value="Cancel" action="{!cancel}"/>
                </apex:pageBlockButtons>  
                
                
              
                                  
       <apex:pageblockSection >     
          
   
            <apex:pageBlockTable style="width:100%" value="{!memberAddList}" var="memb">     
                <apex:column headerValue="Match Day Ops" headerClass="colHeadr">
                    <apex:inputField value="{!memb.Match_Day_Ops__c}" style="width:325px" />
                </apex:column>
                <apex:column headerValue="Type" headerClass="colHeadr">
                    <apex:inputField value="{!memb.Type__c}"/>
                </apex:column>
                 <apex:column headerValue="Priority" headerClass="colHeadr">
                    <apex:inputField value="{!memb.Priority__c}"/>
                </apex:column>
                  <apex:column headerValue="Date/Time Opened" headerClass="colHeadr">
                    <apex:inputField value="{!memb.Date_Time__c}"/>
                </apex:column>
                <apex:column headerValue="Incident Open" headerClass="colHeadr">
                    <apex:inputField value="{!memb.Incident__c}" style="width: 200px; height: 80px"/>
                </apex:column>

             <apex:column headerValue="Date/Time Closed" headerClass="colHeadr">
                    <apex:inputField value="{!memb.Date_Closed__c}"/>
                </apex:column> 
                <apex:column headerValue="Incident Closed" headerClass="colHeadr">
                    <apex:inputField value="{!memb.Incident_Closed__c}" style="width: 200px; height: 80px"/>
                </apex:column>
                <apex:column headerValue="Reported To" headerClass="colHeadr">
                    <apex:inputField value="{!memb.Reported_To__c}"/>
                </apex:column>
                <apex:column headerValue="Reported By" headerClass="colHeadr">
                    <apex:inputField value="{!memb.Reported_By__c}"/>
                </apex:column>  
                
                </apex:pageBlockTable> 

        </apex:pageblockSection>    
           
        <apex:pageblockSection columns="1" >
            <apex:pageblockSectionItem >
<apex:commandLink value="Add Row" action="{!addRow}" reRender="membAdd" />  
           
            </apex:pageblockSectionItem>        
        </apex:pageblockSection>
    </apex:pageBlock>
</apex:form>

</apex:page>

 
Hi, 

I have a test class that has a compile error when I try to save. I was wondering if anybody could help.
Many thanks

Class:
public class MatchReadyImage {

public Match_Day_Check_List__c obj {get; set; }


public MatchReadyImage(){
           obj = [Select Id, Match_Day_Ready_Status__c  From Match_Day_Check_List__c Where Name = 'Everton V West Ham United Goodison Park EPL 2013-05-12'];
    }
}

Test Class:
@isTest(seeAllData = true)
private class MatchReadyImageTest {

    private static void MatchReadyImage() {
        Match_Day_Check_List__c mdckl = new Match_Day_Check_List__c(
            name = 'Everton V West Ham United Goodison Park EPL 2013-05-12',
             Fixture__c = [select id from CS_Fixture__c limit 1].id,
             Match_Plan__c = [select id from Pre_Match__c limit 1].id);

        insert mdckl;       
      
        System.assert((new MatchReadyImage).obj != null);
    }

}

 
Hi all, I was wondering if you could help me create a test class for the clontroller seen below. Any help would be appreciated,

Many thanks.
 
public class IncidentLogPopup
{ 

 public List<Incident_Log__c> memberList {get;set;}
    public List<Incident_Log__c> memberAddList {get;set;}
    public String memberName {get;set;} 
    public string searchstring {get;set;} 

    
    public PageReference cancel() {
        return null;
    }


    public IncidentLogPopup() {

    }
    
   
    public IncidentLogPopup(ApexPages.StandardController controller) {
        String sql = 'SELECT Match_Day_Ops__c, Date_Time__c, Date_Closed__c, Type__c, Priority__c, Incident__c, Reported_to__c, Reported_By__c, Opened_Closed_Status__c FROM Incident_Log__c';
        memberList = Database.Query(sql);
        memberAddList = new List<Incident_Log__c>();
        memberAddList.add(new Incident_Log__c(Match_Day_Ops__c = 'a0Gf000000111CV', Date_Time__c = DateTime.Now()));
         
        
    }
    
    public void AddRow()
    {
        memberAddList.add(new Incident_Log__c(Match_Day_Ops__c = 'a0Gf000000111CV', Date_Time__c = DateTime.Now()));
        
    } 
    
    Public Pagereference Save(){
        insert memberAddlist;
        PageReference page = new Pagereference('/a0G/o');
                     page.setRedirect(true);
            return page;
  }
   

        
   }

 
Hi,

I was wondering if its possible to update the quantity sold field when certain criteria is met. I have created one and for some reason it does not seem to trigger. I have attached an image of the workflow i have created. When a product is added to the opportunity i want the quantity to availibility to decrement by 1.

Many thanksUser-added imageUser-added image
Hi,

I am currently in the process of creating a booking system. It should allow people to choose a specific area (Tennis Court) and time (9:00am) from two different picklists. However now that that area has been booked, there needs to be a way of not letting that area be availible for selection untill the time has passed. I have tried performing this with a trigger, however it does not allow the pricebook to be selected, nor does it let a lead conversion take place. I am unsure weather this can be done through workflows and validation rules. The code to my trigger is as follows:

trigger TriggerToValidateTennisCourt on opportunity (BEFORE INSERT, BEFORE UPDATE)
    {
        LIST<opportunity> li = [SELECT area_to_book__c, Start_Time__c FROM opportunity WHERE area_to_book__c = 'Bowling Green'];
        for(opportunity o :trigger.new)
        {
         if(o.area_to_book__c == 'Tennis Court' && o.Start_Time__c == '09:00' || o.Start_Time__c == '10:00'|| o.Start_Time__c == '11:00'|| o.Start_Time__c == '12:00'|| o.Start_Time__c == '13:00'|| o.Start_Time__c == '14:00'|| o.Start_Time__c == '15:00'|| o.Start_Time__c == '16:00'|| o.Start_Time__c == '17:00'|| o.Start_Time__c == '18:00'|| o.Start_Time__c == '19:00'|| o.Start_Time__c == '20:00')
         {
          for(opportunity existrecord :li)
          {
              if(existrecord.area_to_book__c == o.area_to_book__c){
              o.area_to_book__c.adderror('This area is fully booked. Please select another time.');
              }
              else if(o.area_to_book__c == 'Bowling Green' && o.Start_Time__c == '09:00' || o.Start_Time__c == '10:00'|| o.Start_Time__c == '11:00'|| o.Start_Time__c == '12:00'|| o.Start_Time__c == '13:00'|| o.Start_Time__c == '14:00'|| o.Start_Time__c == '15:00'|| o.Start_Time__c == '16:00'|| o.Start_Time__c == '17:00'|| o.Start_Time__c == '18:00'|| o.Start_Time__c == '19:00'|| o.Start_Time__c == '20:00')
              {
          for(opportunity existrecordBG :li)
          {
             if(existrecordBG.area_to_book__c == o.area_to_book__c){
              o.area_to_book__c.adderror('This area is fully booked. Please select another time.');
              }
          }
         }
        }

    }
    }
    }

Many thanks