You need to sign in to do that
Don't have an account?
albonill
Need help with trigger
Hello,
I need assistance in the creation of a trigger that will not allow the deletion of an Opportunity under the following circumstances:
- If there is an Agreement Name (Name) (echosign_dev1__SIGN_Agreement__c is object)
- Or if there is a Sales Order No (Name) (Sales_Order__c is object)
- Or if there is an Sales Invoice No (Name) (Sales_Invoice__c is the object)
- Or if there is an attachment present in the Agreement
Thank you for your help.
Regards,
Alex
Apex script
If it works for you , mark this as resolved.
Thanks ,
bForce
All Answers
Hello, Alex,
This sounds like pretty serious development you want done. You'll probably get better help by securing a small budget and posting the job on a site like Elance.
Hi Alex,
trigger deleteTest on Opportunity (before delete) {
Set<id> agreeAttachment = new set<id>();
for(Attachment a : [select id, name, parentid from Attachment]){
agreeAttachment.add(a.ParentId);
}
for (Opportunity opp : trigger.old){
//Assuming that the name of the loop-up fields on the Opportunity are as echosign_dev1__SIGN_Agreement__c, Sales_Order__c and Sales_Invoice__c
if(opp.echosign_dev1__SIGN_Agreement__c != null || opp.Sales_Order__c != null || opp.Sales_Invoice__c!=null || agreeAttachment.contains(opp.echosign_dev1__SIGN_Agreement__c)){
opp.addError('enter your error message here!!');
}
}
}
Hope this helps!
Regards
Sam
Apex script
If it works for you , mark this as resolved.
Thanks ,
bForce
Above script will work for bulk as well.
Thanks,
bForce
Hello bForce,
I really appreciate your help. There was only a minor problem. I had to change Opportunity__c to echosign_dev1__Opportunity__c since that is how the Opportunity is referenced within the Agreement.
The trigger saved just fine so now I just have to test things out. Two thumbs up!!!
Regards,
Alex
It willwork perfectly for bulk data as well
Thanks,
bForce