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
ethan huntethan hunt 

Trigger For Case

Hi,

 

I am writing a trigger where if Case is Closed then the account related to that case will get deleted.

 

trigger Case2Account on Case (after update)
{
list<account> acclist = new list<account>();

for(case ca:trigger.old)
{

if (ca.status='Closed')
{
Account acc = new Account();
acc.Id = ca.AccountId;
delete acc;
}
}
}

 

Please help

sandy_salesfdc1sandy_salesfdc1

trigger Case2Account on Case (after update)
{
list<account> acclist = new list<account>();

try{

for(case ca:trigger.old)
{

if (ca.status='Closed')
{
Account acc = new Account();
acc.Id = ca.AccountId;
acclist.add(acc);
}
}

delete acclist ;

}

catch(exception e){

}
}

PremanathPremanath

I think this might be work...

trigger Case2Account on Case (after update)
{
list<account> acclist = new list<account>();
List<Id> accid=new List<Id>();
try{
for(case ca:trigger.New)
{
if (ca.status='Closed')
{
accid.add( ca.AccountId);
}
}
List<Account> acc=[Select id,Name from Account where id in:accid];
for(Account a:acc){
acclist.add(a);
}
delete acclist;
}
catch(exception e){
}
}