You need to sign in to do that
Don't have an account?
Bryan Revelant
Apex Trigger on Reassign Approvals
Apex Trigger on Reassign Approvals,
I have created an Add error on if the users try and reassign to a different approver. The code however doesnt seem to fire on reassign. I thought that If i said that the orginalActorid deosnt match the Actorid then fire a adderror when clicked.
Then I thought that if steps = reassigned value then through error but it doesnt fire either. Any help would be great. i would rather not create a VF but i guess i could try if this is not possible.
trigger ADRUserReassign on ADRUser__c (after update) {
public String ADendid;
list<ADRUser__c> ad =[Select id, Name, User__c from ADRUser__c where id =:ADendid];
list<ADRUser__c> ad2Update = new list<ADRUser__c>();
map<id, ADRUser__c> ADaddMap = new map<id, ADRUser__c>([Select id from ADRUser__c where id =:ADendid]);
list<ProcessInstance> PI = new list<ProcessInstance>();
map<id, id> PIVaddMap = new map<id, id>();
system.debug(' ID Value on Target Object ' + ADaddMap);
for (ProcessInstance lstProcess : [Select id, Status, CreatedDate, TargetObjectId,
(Select Id,ProcessInstanceId, StepStatus,
Comments,OriginalActorId,ActorId
From steps order by CreatedDate DESC)
From ProcessInstance
where targetobjectid=:ADendid order by CreatedDate DESC]){
PI.add(lstProcess);
PIVaddMap.put(lstProcess.TargetObjectId, lstProcess.id);
}
for(ProcessInstance lstPI : PI){
// if(lstPI.Status=='Reassigned'){
for(ProcessInstanceStep lstSteps : lstPI.Steps){
// if(lstSteps.OriginalActorId != lstSteps.ActorId){
if(lstSteps.StepStatus == 'Reassigned'){
lstPI.addError('You cannot reassign - try again');
id ADRUserAddId = PIVaddMap.get(lstPI.TargetObjectId);
ADRUser__c AAdd = ADaddMap.get(lstPI.TargetObjectId);
lstPI.addError('You cannot reassign - try again');
// if (lstSteps.OriginalActorId != lstSteps.ActorId){
// lstSteps.addError('You cannot reassign - try again');
}
}
}
}
// }
// } //End void
//}//End main
I have created an Add error on if the users try and reassign to a different approver. The code however doesnt seem to fire on reassign. I thought that If i said that the orginalActorid deosnt match the Actorid then fire a adderror when clicked.
Then I thought that if steps = reassigned value then through error but it doesnt fire either. Any help would be great. i would rather not create a VF but i guess i could try if this is not possible.
trigger ADRUserReassign on ADRUser__c (after update) {
public String ADendid;
list<ADRUser__c> ad =[Select id, Name, User__c from ADRUser__c where id =:ADendid];
list<ADRUser__c> ad2Update = new list<ADRUser__c>();
map<id, ADRUser__c> ADaddMap = new map<id, ADRUser__c>([Select id from ADRUser__c where id =:ADendid]);
list<ProcessInstance> PI = new list<ProcessInstance>();
map<id, id> PIVaddMap = new map<id, id>();
system.debug(' ID Value on Target Object ' + ADaddMap);
for (ProcessInstance lstProcess : [Select id, Status, CreatedDate, TargetObjectId,
(Select Id,ProcessInstanceId, StepStatus,
Comments,OriginalActorId,ActorId
From steps order by CreatedDate DESC)
From ProcessInstance
where targetobjectid=:ADendid order by CreatedDate DESC]){
PI.add(lstProcess);
PIVaddMap.put(lstProcess.TargetObjectId, lstProcess.id);
}
for(ProcessInstance lstPI : PI){
// if(lstPI.Status=='Reassigned'){
for(ProcessInstanceStep lstSteps : lstPI.Steps){
// if(lstSteps.OriginalActorId != lstSteps.ActorId){
if(lstSteps.StepStatus == 'Reassigned'){
lstPI.addError('You cannot reassign - try again');
id ADRUserAddId = PIVaddMap.get(lstPI.TargetObjectId);
ADRUser__c AAdd = ADaddMap.get(lstPI.TargetObjectId);
lstPI.addError('You cannot reassign - try again');
// if (lstSteps.OriginalActorId != lstSteps.ActorId){
// lstSteps.addError('You cannot reassign - try again');
}
}
}
}
// }
// } //End void
//}//End main
As per the salesforce docs addError() method works only with Trigger.new and Trigger.old.Go through the link to learn more :-
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_sobject.htm#apex_System_SObject_addError
Go through the below link which might help you :-
https://developer.salesforce.com/forums/ForumsMain?id=906F00000008xsiIAA
Thanks,
Indrasen
Thanks,
Indy