简体   繁体   English

单击标准销售人员聊天页面中的批准/拒绝链接后,是否可以显示“定制VF”页面?

[英]Is it Possible to display Custom VF page upon Clicking Approve/Reject Link in Standard sales force chatter page?

Please let me know is it possible to display the custom visualforce page upon clicking the Approve/Reject Link on the record instead of displaying standrad Salesforce Approve page. 请让我知道,单击记录上的批准/拒绝链接可以显示自定义visualforce页面,而不是显示标准的Salesforce批准页面。

If it is possible then please let me know how that could be acheived? 如果可能的话,请让我知道如何实现?

Follow the below approach to override standard approval process page. 请遵循以下方法来覆盖标准批准过程页面。

  1. Create a custom visualforce page: start by copying the standard approval/rejection page. 创建自定义visualforce页面:首先复制标准的批准/拒绝页面。
  2. Create a controller with methods for approve/reject/cancel. 使用批准/拒绝/取消方法创建控制器。 The Approval Process API is available in the Apex reference book. Apex参考书中提供了审批流程API。
  3. Create a home page component with Javascript to override the "Approve/Reject" button on Lead. 使用Javascript创建主页组件,以覆盖Lead上的“批准/拒绝”按钮。
  4. Add this home page component in home page layout. 在主页布局中添加此主页组件。

VisualForce Page VisualForce页面

<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>

Controller 调节器

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;
    }
}

Home Page Component 主页组件

<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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM