function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
amateur1amateur1 

bulkification of my trigger

hi all 

 

i have written this trigger and i tried to bulkify it using sets and maps and i tried with 100 percent effort on it to bulkify it but couldnt do it because i have minimum knowledge on how to use maps please some on if u r patient enough re write my code and please comment so i will be able to understand how to bulkify a trigger and  especially how to use maps please dont give me reference links as i already read all those but could gain minimum knowledge and couldnt use it to bulkify my trigger

 

trigger WOW_Block_Time on Appointment__c (before Insert,before update)
 {
for(Appointment__c APP : Trigger.new)
{

Time_blocks__c[] TBS2 = [select id,Branch__c,Date__c,Staff__c,RecordTypeId,Appt_24_Frm_Hour__c,Appt_24_Frm_Min__c,Apt_24_To_Hour__c,Apt_24_To_Min__c from Time_blocks__c where 
(Branch__c =:APP.Branch__c or Branch__c =:null)  AND (Date__c =:APP.Appt_Date__c or Date__c=:null)  AND 
(staff__c =:App.Doctor__c or staff__c=:null) AND
(RecordTypeId='012O0000000ClgY' or RecordTypeId='012O0000000CldK' or RecordTypeId='012O0000000CldF' or RecordTypeId='012O0000000ClhH')
AND (Appt_24_Frm_Hour__c !=:null or Appt_24_Frm_Hour__c=:null)  AND  (Apt_24_To_Hour__c !=:null or Apt_24_To_Hour__c=:null) ];

for(Time_blocks__c TBS3:TBS2)
{

if(tbs3.Branch__c ==APP.Branch__c && tbs3.Date__c==APP.Appt_Date__c && tbs3.staff__c ==null && tbs3.Appt_24_Frm_Hour__c ==null &&tbs3.Apt_24_To_Hour__c ==null &&
tbs3.RecordTypeId=='012O0000000CldF')
{
if(TBS2.size()>0)
{
App.adderror('Blocked Branch!!');
}
}

if(tbs3.Branch__c ==APP.Branch__c && tbs3.Date__c==APP.Appt_Date__c && tbs3.staff__c ==App.Doctor__c&& tbs3.Appt_24_Frm_Hour__c ==null &&tbs3.Apt_24_To_Hour__c ==null &&
tbs3.RecordTypeId=='012O0000000CldK')
{
if(TBS2.size()>0)
{
App.adderror('Blocked staff!!');
}
}

if(tbs3.Branch__c==null && tbs3.Date__c==APP.Appt_Date__c && tbs3.staff__c==null&& tbs3.Appt_24_Frm_Hour__c==null &&tbs3.Apt_24_To_Hour__c ==null &&
tbs3.RecordTypeId=='012O0000000ClhH')
{
if(TBS2.size()>0)
{
App.adderror('Blocked Date!!');
}
}

if(tbs3.Branch__c ==APP.Branch__c && tbs3.Date__c==APP.Appt_Date__c && tbs3.staff__c ==App.Doctor__c&& 
tbs3.Appt_24_Frm_Hour__c !=null &&tbs3.Apt_24_To_Hour__c!=null &&
tbs3.RecordTypeId=='012O0000000ClgY')
{
if(TBS2.size()>0)
{
integer fromhr=integer.valueof(tbs3.Appt_24_Frm_Hour__c);
integer frommin=integer.valueof(tbs3.Appt_24_Frm_Min__c);
integer tohr=integer.valueof(tbs3.Apt_24_To_Hour__c );
integer tomin=integer.valueof(tbs3.Apt_24_To_Min__c);

integer hr=integer.valueof(app.Appt_Hour__c);
integer min=integer.valueof(app.Appt_Minute__c);

if(app.Appt_AM_PM__c=='AM')
{
if((hr>=fromhr &&hr<=tohr&&min>=frommin&&min<=tomin)||(hr>fromhr &&hr<tohr)||  (hr>=fromhr &&hr<tohr&&min>=frommin&&min>=tomin)||(hr>fromhr &&hr<=tohr&&min<=frommin&&min<=tomin))
{
app.adderror('time blocked');
}
}
else if(app.Appt_AM_PM__c=='PM')
{
if(hr==12)
{
hr=12;
}
else
{
hr=hr+12;
}
if((hr>=fromhr &&hr<=tohr&&min>=frommin&&min<=tomin)||(hr>fromhr &&hr<tohr)||  (hr>=fromhr &&hr<tohr&&min>=frommin&&min>=tomin)||(hr>fromhr &&hr<=tohr&&min<=frommin&&min<=tomin))
{
app.adderror('time blocked1');
}

}


}

}


}

}
}