• wells wang
  • NEWBIE
  • 10 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
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做一个绑定,用来判断是否是有新的审批步骤,从而确定是否需要暴露新的字段给用户操作
        }
   }
   //下面获取需要暴露的字段API名字
   if(set_campId.size()>0){  
        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_APIupdate.put(pi.TargetObjectId,APIName);//封装成map,然后再查询出campain的字段,并更新campain字段
              Map_CurrentApprovaler.put(pi.TargetObjectId,pi.Steps[currentStep -1].OriginalActorId);
              Map_setp.put(pi.TargetObjectId,pi.Steps.size());           
           }
        }
   }
   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);
           }
   }
 
}
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做一个绑定,用来判断是否是有新的审批步骤,从而确定是否需要暴露新的字段给用户操作
        }
   }
   //下面获取需要暴露的字段API名字
   if(set_campId.size()>0){  
        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_APIupdate.put(pi.TargetObjectId,APIName);//封装成map,然后再查询出campain的字段,并更新campain字段
              Map_CurrentApprovaler.put(pi.TargetObjectId,pi.Steps[currentStep -1].OriginalActorId);
              Map_setp.put(pi.TargetObjectId,pi.Steps.size());           
           }
        }
   }
   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);
           }
   }
 
}