You need to sign in to do that
Don't have an account?
txmapp
trigger after delete error help me
hi
i have a error in this trigger
is for 2 objects that is related by a lookup filed or a master detail
Vacante__c , and Asignados __c here is the lookup field that search a Vacante__c
that i want to do is prevent delete a Vacante__c when there is one or more records of the object Asignados__c related to the record that i want to delete
trigger preventDelete on Vacante__c(before delete){ Set<ID> vacant = New Set<ID>(); For(Asignados__c a : [Select Vacante__c From Asignados__c Where Vacante__c IN :trigger.old]) vacant.add(a.Vacante__c); For(Vacante__c v : trigger.old){ If(vacant.containsKey(v.ID)) v.addError('You cannot delete this'); } }
but i get this error Method does not exist or incorrect signature: [SET<Id>].containsKey(Id)
can somebody help me???
Here to go
This code is tested , If you need any other help, please let us know .
Thanks ,
bForce
All Answers
For set Data Type,
Apex having some different methods to check , whether that specific value exist or not , you can use below signature
hi thanks for your help
but my trigger not fire, allows to delete the Vacante__c
i have 1 record that is related to the vacante__c that i want to delete if the trigger run i can't delete for the child
the master detail is in the object Asignados__c
can you halpe me??
could you please post your requirement in brief ,
Also provide all related API names for both object and fields
I will provide script for it .
Thanks,
bForce
namespace txmrecruitment
object Vacant__c
object Asignados__c
onject Aspirante__c
Asignados__c
*Vacante__c masterdetail to Vacante__c
*Aspirante__c masterdetail to Aspirante__c
i want to prevent delete a record or records in Vacante__c if have one or more child, the child is the records of object Asignados__c
i want to create a trigger before delete
if the record has one or more genereate error or alert 'this Vacante can't be delete '
Here to go
This code is tested , If you need any other help, please let us know .
Thanks ,
bForce
thanks for your help
i checked and prove but the record is deleted and have one child
i don't know what to do
i have 4 records of Vacante_c then i created other 4 records on Asignados__c that is related with master detail for each record on Vacante__c
i hace 3 days with this problem
any suggestion??
ohh cmon,
This code is tested properly and It works :)
Could you please post your trigger code... and make sure your trigger is active .
you can get back to me at balasahebwani@gmail.com
Thanks,
bForce
thanks for your help friend
i solved my problem
thanks
Hey ,
I just saw snapshot or your trigger, please change the error message as per your business need ,
Happy coding..
Cheers,
Bala