Triggers 从Salesforce中的活动流程实例对象更新自定义对象

Triggers 从Salesforce中的活动流程实例对象更新自定义对象,triggers,salesforce,apex-code,Triggers,Salesforce,Apex Code,此触发器从流程实例对象中提取值,将其存储在列表中,并更新自定义对象上的字段。问题是,为了查看值,用户必须更新并保存记录。通常,我会在流程实例对象上添加“更新后”触发器,但Salesforce不允许这样做 如有任何帮助或建议,将不胜感激 在服务请求上触发更新\u供应器(更新前){ for(服务请求:触发器。新建){ List pi=[从ProcessInstance中选择Id,CreatedDate,其中TargetObjectId=:sr.Id按CreatedDate描述限制1排序]; 列表op

此触发器从流程实例对象中提取值,将其存储在列表中,并更新自定义对象上的字段。问题是,为了查看值,用户必须更新并保存记录。通常,我会在流程实例对象上添加“更新后”触发器,但Salesforce不允许这样做

如有任何帮助或建议,将不胜感激

在服务请求上触发更新\u供应器(更新前){

for(服务请求:触发器。新建){
List pi=[从ProcessInstance中选择Id,CreatedDate,其中TargetObjectId=:sr.Id按CreatedDate描述限制1排序];
列表op=[从ProcessInstanceStep中选择Id、StepStatus、ActorId、OriginalActorId、CreatedDate,其中ProcessInstanceId=:pi[0]。按CreatedDate描述限制1排序的Id];
如果(操作大小()>0){
//System.debug('Hello'+sr.Provisioner_uuc+''+op[0].StepStatus+''+op[0].ActorId+''+op[0].OriginalActorId+''+op[0].CreatedDate);
sr.Provisioner_uuc=op[0].ActorId;
}       
}

}

将update\u Provisioner触发器更改为更新后事件。 再次更新trigger.new列表,并按静态标志停止循环

大概是这样的:

trigger update_Provisioner on Service_Request__c (after update) {
    if(flag)
      return;
    flag=true;
    for(Service_Request__c sr:Trigger.new){

List <ProcessInstance> pi = [SELECT Id, CreatedDate from ProcessInstance where TargetObjectId = :sr.Id ORDER BY CreatedDate DESC limit 1];
List <ProcessInstanceStep> op = [SELECT Id, StepStatus, ActorId, OriginalActorId, CreatedDate FROM ProcessInstanceStep where ProcessInstanceId = :pi[0].Id ORDER BY CreatedDate DESC limit 1];


        if(op.size()>0){

        //System.debug('Hello'+sr.Provisioner__c+' '+op[0].StepStatus + ' '+ op[0].ActorId + ' ' +op[0].OriginalActorId + ' '+ op[0].CreatedDate);
        sr.Provisioner__c = op[0].ActorId;

          }       

}
update trigger.new;
}
在服务请求上触发更新\u供应器(更新后){
国际单项体育联合会(旗)
返回;
flag=true;
for(服务请求高级:触发器。新建){
List pi=[从ProcessInstance中选择Id,CreatedDate,其中TargetObjectId=:sr.Id按CreatedDate描述限制1排序];
列表op=[从ProcessInstanceStep中选择Id、StepStatus、ActorId、OriginalActorId、CreatedDate,其中ProcessInstanceId=:pi[0]。按CreatedDate描述限制1排序的Id];
如果(操作大小()>0){
//System.debug('Hello'+sr.Provisioner_uuc+''+op[0].StepStatus+''+op[0].ActorId+''+op[0].OriginalActorId+''+op[0].CreatedDate);
sr.Provisioner_uuc=op[0].ActorId;
}       
}
更新trigger.new;
}

您是否尝试过直接在启动此操作的审批流程中添加字段更新,而不是在触发器中执行此操作?当我更改触发器“AfterUpdate”时,我将无法修改调用对象的字段,即第14行“sr.Provisioner\uu c=op[0].ActorId;”将抛出错误,因为记录是只读的。
trigger update_Provisioner on Service_Request__c (after update) {
    if(flag)
      return;
    flag=true;
    for(Service_Request__c sr:Trigger.new){

List <ProcessInstance> pi = [SELECT Id, CreatedDate from ProcessInstance where TargetObjectId = :sr.Id ORDER BY CreatedDate DESC limit 1];
List <ProcessInstanceStep> op = [SELECT Id, StepStatus, ActorId, OriginalActorId, CreatedDate FROM ProcessInstanceStep where ProcessInstanceId = :pi[0].Id ORDER BY CreatedDate DESC limit 1];


        if(op.size()>0){

        //System.debug('Hello'+sr.Provisioner__c+' '+op[0].StepStatus + ' '+ op[0].ActorId + ' ' +op[0].OriginalActorId + ' '+ op[0].CreatedDate);
        sr.Provisioner__c = op[0].ActorId;

          }       

}
update trigger.new;
}