+ Start a Discussion
santhosh konathala 17santhosh konathala 17 

Hi Can anybody do the modification for my Trigger?If we try to update an existing one record in an object I want to delete an rest of the records in an object?But the below code not working fine?

Trigger deloldrecords on Restintegration__c(before update)
{
list<Restintegration__c> newlist= new list<Restintegration__c>();

for(Restintegration__c oldacc:Trigger.old)
{
newlist.add(oldacc);
}
delete newlist;
}
Best Answer chosen by santhosh konathala 17
Deepak Pandey 13Deepak Pandey 13
trigger Deleteres on Restintegration__c(after update) {
 List<Id> lstId = new List<Id>();

if(trigger.isupdate)
{
for(Restintegration__c res : trigger.new)
{
if(res.id != null)
{
lstId.add(res.id) ;
}
}
 }

for(Restintegration__c res: Trigger.old){
        List<Restintegration__c > existoppList =  [Select Id from Restintegration__c where  id in = lstId];
        delete existoppList;
    }
 
}

All Answers

sandeep reddy 37sandeep reddy 37
Hi 
santhosh konathala
TRY this coad 
but this is  not good 
trigger checkdelete on Restintegration__c(before update) {
  list<Restintegration__c> newlist;
    if(trigger.isbefore&&trigger.isupdate){
for(Restintegration__c a:Trigger.old)
{
newlist=[select id,Name from account where id!=:a.id];
}
delete newlist;
}
}
ok 
I hope this is help full for u?
 
santhosh konathala 17santhosh konathala 17
Hi Sandeep,

Thanks a lot...

The above code working fine..
Deepak Pandey 13Deepak Pandey 13
trigger Deleteres on Restintegration__c(after update) {
 List<Id> lstId = new List<Id>();

if(trigger.isupdate)
{
for(Restintegration__c res : trigger.new)
{
if(res.id != null)
{
lstId.add(res.id) ;
}
}
 }

for(Restintegration__c res: Trigger.old){
        List<Restintegration__c > existoppList =  [Select Id from Restintegration__c where  id in = lstId];
        delete existoppList;
    }
 
}
This was selected as the best answer