• Bryan Revelant
  • NEWBIE
  • 0 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 6
    Replies
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
Hello,

I need to build a trigger or a VF page that I can insert users into a queue for a custom object. I see that I can see the Object in the Meta Date. But I am not sure on how this should be done.

Select q.SobjectType, q.QueueId, q.Id, q.CreatedById From QueueSobject q
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
Having a bit of an issue with an if else Trigger.

If Rejected --- marked rejected on Parent
If Submitted not all Approved -- Mark Submit
If all Approved -- Approved.


trigger ADRUserTriggerV2 on ADRUser__c (after update) {

    list<ADR__c> ListOfADRRecords;
    set<Id> PrimaryKeyId = new set<Id>();
    for(ADRUser__c ADRUserRecords :trigger.new){
 
  if(trigger.oldmap.get(ADRUserRecords.id).ApproveReject__c != 'Submit'){
     if(ADRUserRecords.ApproveReject__c =='Submit' || ADRUserRecords.ApproveReject__c =='Approved' || ADRUserRecords.ApproveReject__c =='Rejected'){
   
            PrimaryKeyId.add(ADRUserRecords.ADR__c);// you child object must having parent object field, put that field Api Name here
  }
   
    }
    }

   if(!PrimaryKeyId.isEmpty()) {
                list<ADR__c> listOfParentRecordsToUpdate = [select id, Apex_Status__c from ADR__c where Id =: PrimaryKeyId];
                ListOfADRRecords = new list<ADR__c>();
     
             
    
                 
      for(ADRUser__c ADRUserRecords :trigger.new){
    for(ADR__c ADRRecordTOUpdate : listOfParentRecordsToUpdate) {

if (ADRUserRecords.ApproveReject__c =='Rejected' ) {
    ADRRecordTOUpdate.Apex_Status__c = 'Rejected';
} else if (ADRUserRecords.ApproveReject__c =='Submit' || ADRUserRecords.ApproveReject__c =='Approved') {
  ADRRecordTOUpdate.Apex_Status__c = 'Submit';
}  else {
    ADRRecordTOUpdate.Apex_Status__c = 'Approved';
}
ListOfADRRecords.add(ADRRecordTOUpdate);


            Update ListOfADRRecords;
}
          }
   }
    }
    // }