You need to sign in to do that
Don't have an account?
sandeep reddy 37
undelete condeation cheack
I want to check deleted record assocated user id and undeleted record assocated user id must be equql other wise throws error
trigger undeletecheack on Account (after delete,after undelete) {
set<id> personids=new set<id>();
for(account c:trigger.old){
if(trigger.isafter&&trigger.isdelete){
user u=[select id,name from user where id=:userinfo.getUserId()];
personids.add(u.id);
}
}
for(account aa:trigger.new){
if(trigger.isafter&&trigger.isundelete){
user u2=[select id,name from user where id=:userinfo.getUserId()];
list<user> lu=[select id,name from user where id=:personids];
for(user i:lu){
if(i.id==u2.id){
}
}
}
}
}
advance thanks
trigger undeletecheack on Account (after delete,after undelete) {
set<id> personids=new set<id>();
for(account c:trigger.old){
if(trigger.isafter&&trigger.isdelete){
user u=[select id,name from user where id=:userinfo.getUserId()];
personids.add(u.id);
}
}
for(account aa:trigger.new){
if(trigger.isafter&&trigger.isundelete){
user u2=[select id,name from user where id=:userinfo.getUserId()];
list<user> lu=[select id,name from user where id=:personids];
for(user i:lu){
if(i.id==u2.id){
}
}
}
}
}
advance thanks
for example you want to undelete record from recycle bin running user id and deleted record assocated user id must be equal
thanks
sandeep
This trigger will only allow the owner of the record to delete and undelet the record.
Let me know if that helped.
i got this errror
Validation Errors While Saving Record(s)
There were custom validation error(s) encountered while saving the affected record(s). The first validation error encountered was "Apex trigger srinivasreddy.undeletecheack caused an unexpected exception, contact your administrator: srinivasreddy.undeletecheack: execution of BeforeDelete caused by: System.FinalException: Record is read-only: Trigger.srinivasreddy.undeletecheack: line 4, column 1".
Click here to return to the previous page.
vineet can we perform dml on deleted record
Reference :
https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_calls_queryall.htm.
But writing a future method would be recommended here.
Also, I'm not getting the point to why you want to put such kind of limitation. There seems to be a gap in your implementation, perhaps you may want to revisit your delete permission.
Thanks