You need to sign in to do that
Don't have an account?
JonSimmons
After Undelete Trigger Problem
I'm trying to create a trigger on Asset, after Undelete.
I simply want to set a flag to denote that the record has been undeleted.
I expect that I should be able to do something like the following, but I get an "Attempt to de-reference a null object" error on the for loop line.
trigger Asset_Intercept_UnDelete on Asset (after undelete)
{
for(Asset undeletedAsset : trigger.old)
{
Asset theAsset = [select undeleted__c from Asset where id in :trigger.old];
theAsset.undeleted__c = true;
update theAsset;
}
}
Any help or pointers are greatly appreciated.
Thanks
Jon
Try this:
trigger Asset_Intercept_UnDelete on Asset (after undelete) { //Move the query outside the for loop to avoid any issues with governor limits Asset[] theAsset = [select undeleted__c from Asset where id in :trigger.new]; for(Asset undeletedAsset : theAsset){ undeletedAsset.undeleted__c = true; } //Move the update DML statement outside the for loop update theAsset; }
All Answers
Try this:
trigger Asset_Intercept_UnDelete on Asset (after undelete) { //Move the query outside the for loop to avoid any issues with governor limits Asset[] theAsset = [select undeleted__c from Asset where id in :trigger.new]; for(Asset undeletedAsset : theAsset){ undeletedAsset.undeleted__c = true; } //Move the update DML statement outside the for loop update theAsset; }
Hey, that worked great!
Thanks alot!
Jon
trigger afterundeletecheck on Account (after undelete) {
if(trigger.isafter&&trigger.isundelete){
list<account> a=[select id,name,srinivasreddy__undeleted__c from account where id =:trigger.new];
for(account b:a){
b.srinivasreddy__undeleted__c=true;
a.add(b);
}
update a;
}
}
Hello i am write one trigger on custom object but tigger is not working so please help me
trigger AfterUndeleteUser on UserDetails__c (after upsate)
{
List<UserDetails__c> ud = [select Id, Name, Is_Active__c from UserDetails__c where id in:trigger.new];
for(UserDetails__c UndeleteUser : ud){
UndeleteUser.Is_Active__c = true;
}
Update ud;
}
trigger AfterUndeleteUser on UserDetails__c (before update){
for(UserDetails__c UndeleteUser : trigger.new){
UndeleteUser.Is_Active__c = true;
}
}