+ Start a Discussion
wells wangwells wang 

Can I get approvaler from trigger. after the records update by field update.

I want get the approvaler id in trigger. after the user submit the records to approval.  Could someone can help me. and i attached my trigger code as below, very apprecaiate if someone can help. thanks a lot!

User-added image

trigger Promo_ItemList_af_Up on Campaign (before update) {
  set<id> set_campId = new set<id>();
  String APIName = '';
  String APIType = 'Checkbox;';
  Map<id,Decimal > Map_setp = new Map<id,Decimal>();
  Map<Id,String>  Map_APIupdate = new Map<Id,String> ();
  Map<Id,Id>  Map_CurrentApprovaler = new Map<Id,Id> ();
  List<Campaign> List_update;
   ID recordTypeId = Schema.SObjectType.Campaign.getRecordTypeInfosByName().get('Internal propose item approval promotion').getRecordTypeId();
   System.debug('Get Record type id========' + recordTypeId);//只适用于record type为Item的 // recordtype name =Internal propose item approval promotion
   for(Campaign cm:trigger.new){
       if(cm.recordtypeId == recordTypeId){
            set_campId.add(cm.id);//把campain 封装到set里面
            Map_setp.put(cm.id, cm.CurrentApprovalStep__c);  //对应的审批步骤和campain做一个绑定,用来判断是否是有新的审批步骤,从而确定是否需要暴露新的字段给用户操作
        integer currentStep =0;  
       for(ProcessInstance pi:[Select p.TargetObjectId, p.Status, p.Id, (Select Id, StepStatus,OriginalActorId, ActorId,Actor.UserRole.Name From Steps) step From ProcessInstance p where TargetObjectId =:set_campId and Status = 'Pending']){
          currentStep= pi.Steps.size();
           String Label = pi.Steps[currentStep -1].Actor.UserRole.Name;
           //System.debug('GET actor name Label======' +Label );
           // System.debug('pi.Steps ========= ========= ===== ======= ===== ======= ===== ======= ===== === ===== ======='+ pi.Steps.size() + '===currentStep======'+currentStep);
         if(Map_setp.get(pi.TargetObjectId) != currentStep){ //当有新的step的时候才做更新,如果是相等的情况下,则跳过。
              APIName = PromoUtils.TransferLabelToAPI(Label,'Promotion_Account_List__c');//调用公共方法转换label为API名字
             // System.debug('APIName ===== ===== ===== ===APIName== ===== ===== ======='+ APIName);
              Map_CurrentApprovaler.put(pi.TargetObjectId,pi.Steps[currentStep -1].OriginalActorId);
   if(Map_APIupdate !=null && Map_APIupdate.size()>0){
           for(Campaign cm: trigger.new){
                cm.PromoField__c =cm.PromoField__c + Map_APIupdate.get(cm.id);
                  cm.PromoFieldType__c =cm.PromoFieldType__c + APIType;
                  cm.CurrentApprovaler__c = Map_CurrentApprovaler.get(cm.id);
                  cm.CurrentApprovalStep__c = Map_setp.get(cm.id);

All Answers

Eswar Prasad@Sfdc11Eswar Prasad@Sfdc11
HI Wells wang,

Pls see below post we will get idea.


If you get the answer, please mark it as the correct answer. It will be a help to others who are facing the same problem later.

Eswar Prasad

wells wangwells wang
Hi Eswar,

Thanks  for your help, but still not get the correct answaner. 

i just want get the the approvaler id in trigger which the approval process submited by standard approval process.
after sumbited the campain records. the system has assigned to the approvaler.  But between after submited the process and approvaler aproval. i want get the approvaler id and update the id to campain records. Because i will use the id to process other process as required.

In other words, can I get the approvaler id before the approvaler approval the records?  seems there are no API to reference to the approvaler id.