+ Start a Discussion
Vipin  PulinholyVipin Pulinholy 

Trigger on opportunity to delete contact role (Person Account) not working

Hi ,
I am trying to create an update trigger on opportunity. 
if any opportunity is updated i wanted to check if the assosicated Person Account (contact)
with this opportunty is present in the OpportunityContactRole  and if so delete the records from OpportunityContactRole


Here is the trigger that I worte:


trigger deleteOppContRole on Opportunity (after update) {
    for (Integer i = 0; i < Trigger.old.size(); i++) {
        try {
            //replace OppLineId__c with actual refference name.
            OpportunityContactRole [] oDWs = [select id from OpportunityContactRole where OpportunityId = :trigger.old[i].id and ContactId=:trigger.old[i].Account.PersonContactId ];
            delete oDWs;
        } catch (System.QueryException ex) {
            //Do Nothing - There must not have been any to delete.


Looks like the trigger is not getting the value ":trigger.old[i].Account.PersonContactId" so this is not working as expected. (There is no error, but not functioning correctly)


The value printed in debug log  is 'null' for 'trigger.old[i].Account.PersonContactId'.

Can anyone tell me what's worng with this code and how to fix this ?

Message Edited by das on 03-11-2009 02:46 PM
Message Edited by das on 03-11-2009 02:47 PM
Message Edited by das on 03-12-2009 09:22 AM