You need to sign in to do that
Don't have an account?
pfep
help on trigger
i need a trigger which can have following behavior
1. Allow engagements with a record type of "interest form" and status of "Prospect" to be deleted.
2. Prevent engagements with a record type othe than "Interest form" and status of "Prospect" from being deleted.
intrest form and prospect is record type.
engagement is custom object( engagement_c)
basic debugging
trigger checkDelete on Engagement__c(before Delete){
RecordType[] RT = [Select Name From RecordType Where sObjectType = 'engagement__c' and Name = 'Interest Form' and isActive = true LIMIT 1];
for(Engagement__c e : trigger.new){
if(!rt.isEmpty()){
if(e.RecordTypeID == RT[0].id && e.Status__c == 'Prospect')
e.addError('You cannot delete this record');
}else{
e.addError('Contact System Admin, there was an error finding the correct RecordType for this validation');
}
}
}
All Answers
trigger checkDelete on Engagement__c(before Delete){
ID RT = [Select Name From RecordType Where sObjectType = 'engagement__c' and Name = 'Interest Form' and isActive = true LIMIT 1];
for(Engagement__c e : trigger.new){
if(e.RecordTypeID = RT && e.Status__c = 'Prospect')
e.addError('You cannot delete this record');
}
}
This is what i am facing:
Description:
Duplicate engagement records are generated in Salesforce when applicants submit more than one interest form. Using permission sets, we can allow specific users to delete engagements but We want to prevent those users from mistakenly deleting engagements of current students, alumni or students who were referred out.
Behavior:
1. Allow engagements with a record type of "interest form" and status of "Prospect" to be deleted.
2. Prevent engagements with a record type other than "Interest form" and status of "Prospect" from being deleted.
So this trigger does work on this requirement as mentioned? will this also prevent duplicating engagement records also? or do i need to do something else? or this is perfectly fine.
plz suggest me.
thank you
It will work for requirement. It does not prevent duplicates
when i put this trigger in engagement it shows error.
What error does it show?
Error: Compile Error: Illegal assignment from LIST<RecordType> to Id at line 7 column 1
Opps...
trigger checkDelete on Engagement__c(before Delete){
RecordType[] RT = [Select Name From RecordType Where sObjectType = 'engagement__c' and Name = 'Interest Form' and isActive = true LIMIT 1];
for(Engagement__c e : trigger.new){
if(!rt.isEmpty()){
if(e.RecordTypeID = RT[0].id && e.Status__c = 'Prospect')
e.addError('You cannot delete this record');
}else{
e.addError('Contact System Admin, there was an error finding the correct RecordType for this validation');
}
}
}
still it is not working.(
basic debugging
trigger checkDelete on Engagement__c(before Delete){
RecordType[] RT = [Select Name From RecordType Where sObjectType = 'engagement__c' and Name = 'Interest Form' and isActive = true LIMIT 1];
for(Engagement__c e : trigger.new){
if(!rt.isEmpty()){
if(e.RecordTypeID == RT[0].id && e.Status__c == 'Prospect')
e.addError('You cannot delete this record');
}else{
e.addError('Contact System Admin, there was an error finding the correct RecordType for this validation');
}
}
}
thank you