我在Opportunity对象上创建了一个自定义按钮(URL),它会在visualforce页面中重定向我以创建新任务。我试图从URL获取参数值,以填充来自opportunity的一些值,但它不起作用。我没有使用控制器。以下是URL:
/apex/TaskPage?who_id={!Opportunity.AccountId}&what_id={!Opportunity.Id}&retURL={!Opportunity.Id}这是我的visualforce页面:
<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>
有谁能帮帮我吗?谢谢
发布于 2017-03-07 18:22:39
您可以使用以下语法从URL参数中读取值
{!$CurrentPage.parameters.testParam} 发布于 2017-03-07 21:40:19
您可以使用URL黑客来设置值(这就是您正在尝试做的事情?),但这是不安全的/不完整的,因此不推荐这样做。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>
`https://stackoverflow.com/questions/42629646
复制相似问题