0

我在 Opportunity 对象上创建了一个自定义按钮(URL),它将我重定向到一个 visualforce 页面以创建一个新任务。我正在尝试从 URL 获取参数的值,以便从机会中按每个值填充一些值,但它不起作用。我没有使用控制器。这是网址:

/apex/TaskPage?who_id={!Opportunity.AccountId}&what_id={!Opportunity.Id}&retURL={!Opportunity.Id}

这是我的视觉力量页面:

<apex:page standardController="Task">
<apex:form >
    <apex:pageBlock title="New Task">
        <apex:pageBlockButtons >
            <apex:commandButton action="{!save}" value="Save"/>
        </apex:pageBlockButtons>
        <apex:pageBlockSection columns="2" title="Task Information"> 
            <apex:inputField value="{!Task.OwnerId}" id="userName" required="true"/>
            <apex:inputField value="{!Task.Status}"/> 
            <apex:inputField value="{!Task.Subject}"/>
            <apex:inputField value="{!Task.WhatId}"/>
            <apex:inputField value="{!Task.ActivityDate}"/>
            <apex:inputField value="{!Task.WhoId}"/>
            <apex:inputField value="{!Task.Priority}"/>
        </apex:pageBlockSection>
        <apex:pageBlockSection title="Description Information">
            <apex:inputField value="{!Task.Description}"/>
            <apex:inputField value="{!Task.Test__c}"/>
        </apex:pageBlockSection>
    </apex:pageBlock> 
</apex:form>

请问,谁能帮帮我?谢谢

4

2 回答 2

0

您可以使用以下语法从 URL 参数中读取值

{!$CurrentPage.parameters.testParam}  
于 2017-03-07T10:22:38.733 回答
0

您可以使用 URL hacking 设置值(这是您想要做的?),但这是不安全/不完整的,不推荐。Salesforce 可以随时停止支持此功能。

我建议您创建一个控制器扩展,读取其中的页面参数并设置字段。

在扩展类的构造函数中,您可以将字段设置为

`

public class TaskExtension {
    public Task currentTask{get; set;}
    public TaskExtension(ApexPages.StandardController stdController){
       if(currentTask == null) currentTask = new Task();
       currentTask.whoid = ApexPages.currentPage().getParameters().get('who_id');
    }
}

`

Javascript 选项:链接:/apex/TestVF?whatID=001i000000IsaJu&whatName=Infosys

页:

`
    <apex:page standardController="Task">
    <apex:form >
        <apex:pageBlock title="New Task">
            <apex:pageBlockButtons >
                <apex:commandButton action="{!save}" value="Save"/>
            </apex:pageBlockButtons>
            <apex:pageBlockSection columns="2" title="Task Information"> 
                <apex:inputField value="{!Task.OwnerId}" id="userName" required="true"/>
                <apex:inputField value="{!Task.Status}"/>  
                <apex:inputField value="{!Task.Subject}"/>
                <apex:inputField id="whatID" value="{!Task.WhatId}"/>
                <script>
                    document.getElementById('{!$Component.whatID}' + '_lkid').value = '{!$CurrentPage.parameters.whatID}' ;
                    document.getElementById('{!$Component.whatID}' + '_lkold').value = '{!$CurrentPage.parameters.whatName}' ;
                    document.getElementById('{!$Component.whatID}' + '_mod').value = '1' ;
                    document.getElementById('{!$Component.whatID}').value = '{!$CurrentPage.parameters.whatName}' ; 
                </script>
                <apex:inputField value="{!Task.ActivityDate}"/>
                <apex:inputField value="{!Task.WhoId}"/>
                <apex:inputField value="{!Task.Priority}"/>
            </apex:pageBlockSection>
            <apex:pageBlockSection title="Description Information">
                <apex:inputField value="{!Task.Description}"/>
            </apex:pageBlockSection>
        </apex:pageBlock> 
    </apex:form>
    </apex:page>
`
于 2017-03-07T13:40:19.450 回答