• swathi krishnamurthy
  • NEWBIE
  • 0 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies

I'm looking to add an error message to an Opportunity if a user tries to delete it whilst it has any child contracts.

 

Currently my trigger code is as follows

 

trigger ClosedOpportunityPreventDeletion on Opportunity (before delete) {

if (system.Trigger.isDelete){

Opportunity[] Opps = [select id, (select id, Opportunity__c from PCFS__r) from Opportunity where id in :Trigger.oldMap.keySet()];

 

for (Opportunity o : Opps){

if(o.PCFS__r.size()>0){

o.adderror('You cannot delete this Opportunity as it has one or more Customer Forms associated with it');

}

}

}

  Unfortunately, if I use this code, I currently get an error saying "caused by: System.Exception: SObject row does not allow errors".

 

Any ideas?

 

With thanks 

 

 

Message Edited by Big Ears on 07-28-2009 06:54 AM