0

请让我知道是否可以在单击记录上的批准/拒绝链接时显示自定义 visualforce 页面,而不是显示标准 Salesforce 批准页面。

如果可能的话,请让我知道如何实现?

4

1 回答 1

1

按照以下方法覆盖标准审批流程页面。

  1. 创建自定义 visualforce 页面:首先复制标准的批准/拒绝页面。
  2. 创建一个带有批准/拒绝/取消方法的控制器。Apex 参考书中提供了 Approval Process API。
  3. 使用 Javascript 创建主页组件以覆盖潜在客户上的“批准/拒绝”按钮。
  4. 在主页布局中添加这个主页组件。

视觉力量页面

<apex:page controller="ProcessInstanceController" tabStyle="Lead">
    <apex:form>
        <apex:sectionHeader title="Lead" subtitle="{!objLead.Name}"/>
        <apex:pageBlock title="Approve/Reject Approval Request">
            <apex:pageBlockButtons location="bottom">
                <apex:commandButton value="Approve" action="{!approve}"/>
                <apex:commandButton value="Reject" action="{!reject}"/>
                <apex:commandButton value="Cancel" action="{!cancel}"/>
            </apex:pageBlockButtons>  
            <apex:pageBlockSection columns="1">
                <apex:pageBlockSectionItem >
                Name <apex:outputField value="{!objLead.Name}"/>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >
                Lead Owner <apex:outputField value="{!objLead.Owner.Name}"/>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >
                Rejection Reason <font color="red">(Mandatory while Rejection)</font><apex:inputField value="{!objLead.Rejection_Reason__c}"/>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >
                Comments <font color="red">(Mandatory while Rejection)</font> <apex:inputTextArea value="{!objLead.Comments__c}" rows="5" cols="100"/>
                </apex:pageBlockSectionItem>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>

控制器

public class ProcessInstanceController {
    public String processId;
    public String leadId;
    public ProcessInstance objProcessInstance;
    public Lead objLead {get; set;}
    public PageReference redirectPage;
    public ProcessInstanceController(){
        processId = ApexPages.currentPage().getParameters().get('id');
        leadId = ApexPages.currentPage().getParameters().get('leadId');
        objLead = [select Name,Owner.Name,Rejection_Reason__c,Comments__c from Lead where id =:leadId];
        redirectPage = new PageReference('/'+leadId);
    }
    public PageReference Approve(){
        Approval.ProcessWorkitemRequest req = new Approval.ProcessWorkitemRequest();
        req.setComments(objLead.Comments__c);
        req.setAction('Approve');
        req.setWorkitemId(processId);
        Approval.ProcessResult result =  Approval.process(req);
        update objLead;
        return redirectPage ;
    }
    public PageReference Reject(){
        Approval.ProcessWorkitemRequest req = new Approval.ProcessWorkitemRequest();
        req.setComments(objLead.Comments__c);
        req.setAction('Reject');
        req.setWorkitemId(processId);
        Approval.ProcessResult result =  Approval.process(req);
        update objLead;
        return redirectPage ;      
    }
    public PageReference Cancel(){
        return redirectPage;
    }
}

主页组件

<div id="demoContainer">
    <script language="JavaScript">
        try
        {
            var pa=document.getElementById("demoContainer").parentNode.parentNode; pa.style.display = "none";
        }
        catch(err){alert('There was an error on this webpage='+err.description);}
    </script>
    <script language="JavaScript">
        function CustomApproval()
        {
            try
            {
                var str=location.href;
                var leadId=str.substr(str.indexOf(".com/")-0 + 5,15);
                var divid=leadId+'_RelatedProcessHistoryList_body';
                var Approvalprocessdiv=document.getElementById(divid);
                if(Approvalprocessdiv!=null){
                    var originalHTML=Approvalprocessdiv.innerHTML;
                    var newHtml=originalHTML.replace('/p/process/ProcessInstanceWorkitemWizardStageManager?','/apex/ProcessInstanceWorkitemWizard?LeadId='+leadId+'&');
                    Approvalprocessdiv.innerHTML=newHtml;
                }
            }
            catch(err){alert(err);}
        }
        var oldonload = window.onload;
        if (typeof window.onload != 'function')
        {
            window.onload = oldonload;
        } else 
        { 
            window.onload = function() 
            {
                if (oldonload) {
                    oldonload();
                }
                CustomApproval();
            }
        }
    </script>
</div>
于 2015-08-18T15:49:30.097 回答