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
txmapptxmapp 

how to create a trigger that prevent to delete 2 related objects with a lookup fields

i have a problem, i have 2 custom objects
job & applicant , the object job have wiht a lookup field that search one applicant object
and the object applicant also have another lookup field that search a job object
the problem is that i want to prevent delete a job if there are an
applicant that have a reccord with this job

i want to create a trigger
my idea is
1.- get the id of the job that i want to delete
2.- select all the applicant that have the same job in the field job of the applicant
3.- if the result of this select, like a count is >0 generate error "this job can't be delete because
there are applicants that is related with this job"
4.- if the result of the select , like a count is ==0 do nothing, allow to delete

the lookup fields aren't master details , is only a field that is not necesary and can be null when i insert a new record
im new in this topic and i don't know how to create this trigger

 

can somebody help me??