public class ProcessInstanceSolController { public String processId; public String SolId; public ProcessInstance objProcessInstance; public Solution_Programme__c objSol {get; set;} public string Comments {get;set;} public string ApprovalAction {get;set;} public PageReference redirectPage; //初始化 public ProcessInstanceSolController() { processId = ApexPages.currentPage().getParameters().get('id'); //获取当前的工作流ID SolId = ApexPages.currentPage().getParameters().get('SolId'); //获取当前case ID objSol = [select Name,Confirmation_Result__c,Remarks__c,ProcessOfApproval__c from Solution_Programme__c where id =:SolId]; //获取当前Opp对象为了后面更新comments和Reson redirectPage = new PageReference('/'+SolId); } //审批 public PageReference Approval(){ try { System.debug('ApprovalAction:'+ApprovalAction); if(ApprovalAction == 'Approve' || ApprovalAction == 'Reject') { //system.debug('ApprovalAction:'+this.ApprovalAction); // User nextapprover =[select Id from User where username = 'yinghai_guo_neo@sina.com'];//新建立一个object 并mapping关系 if(ApprovalAction == 'Reject'){ ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR, '请填写反馈结果,并按审批按钮')); return null; } if(objSol.Confirmation_Result__c == null){ ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR, '批准之前必须填写反馈结果!')); return null; } objSol.ProcessOfApproval__c = false; update objSol; Approval.ProcessWorkitemRequest approvalNode = new Approval.ProcessWorkitemRequest(); // system.debug('comments:'+objOpp.Comments__c); approvalNode.setComments(Comments); approvalNode.setAction(ApprovalAction); // approvalNode.setNextApproverIds(new Id[]{nextapprover.Id}); approvalNode.setWorkitemId(processId); system.debug('processID'+processId); Approval.ProcessResult result = Approval.process(approvalNode); system.debug('result:'+result.isSuccess()); //system.debug('update objOpp'); } else { //system.debug('ApprovalAction:'+this.ApprovalAction); } } catch(Exception ex) { system.debug('Ex:'+ex.getMessage()); } return redirectPage; } }