function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
CertifiedAdminCertifiedAdmin 

Need help creating a trigger to change a status field when record is deleted

Can someone help me define a trigger (or workflow if available...just can't get it to work) that will updated a field "Status" on our Event record when the event is deleted.

 

We currently use the standard delete button, but I believe there is an "isDeleted" system checkbox I was hoping to work from.  When this box is set to true, I would like the status changed to "Rejected" before it hits the recyble bin.  Is this possible?  We are integrating our activities to SAP CRM, and need to pass the updated status to CRM before it is deleted in SFDC.

 

Any help would be much appreciated!!

Best Answer chosen by Admin (Salesforce Developers) 
Shashikant SharmaShashikant Sharma

Go to -> App Setup ->Activities -> Event Triggers -> new

 

You can directly search Event Trigger in Quick Searck

 

Then Save this trigger, Please cahnge the API Name of statu field as well

 

//Wrtite Same trigger for your object
trigger updateEventStatus on Event (before delete) 
{
    List<Event> listEvent = new List<Event>();
    for(Event e : [Select id from Event where id in: trigger.old])
    {
        //Change this to your status field API Name 
        e.Status__c = 'Rejected';
        listEvent.add(e);
    }
    update listEvent;
}

 

All Answers

Shashikant SharmaShashikant Sharma

You can not do it with workflow as workflow only get execute on insert and update, not on delete.

Here is your trigger

 

//Wrtite Same trigger for your object
trigger updateStatus on Account (before delete) 
{
    List<Account> listAcc = new List<Account>();
    for(Account acc : [Select id from Account where id in: trigger.old])
    {
        //Change this to your status field API Name 
        acc.Status__c = 'Rejected';
        listAcc.add(acc);
    }
    update listAcc;
}

 

 

 

CertifiedAdminCertifiedAdmin

Thanks for your quick reply, Shashikant.

 

Unfortunately, I'm brand new to working with triggers, and I keep getting errors when using your trigger below after I updated with "Event" where it says ACcount in the first line.  Should I replace Account with "event" everywhere it says Account?  Also, what about when you have "acc", is there an abbreviation for Event I should use?

 

Thanks for your help!!

Shashikant SharmaShashikant Sharma

Go to -> App Setup ->Activities -> Event Triggers -> new

 

You can directly search Event Trigger in Quick Searck

 

Then Save this trigger, Please cahnge the API Name of statu field as well

 

//Wrtite Same trigger for your object
trigger updateEventStatus on Event (before delete) 
{
    List<Event> listEvent = new List<Event>();
    for(Event e : [Select id from Event where id in: trigger.old])
    {
        //Change this to your status field API Name 
        e.Status__c = 'Rejected';
        listEvent.add(e);
    }
    update listEvent;
}

 

This was selected as the best answer
CertifiedAdminCertifiedAdmin

ABSOLUTELY PERFECT!!!!

 

 

Thank you so much for your help on this!!!

Shashikant SharmaShashikant Sharma

Your welcome