2017-03-06 124 views
0

我在Opportunity对象上创建了一个自定义按钮(URL),该按钮在Visualforce页面中重定向我以创建一个新的Task。 我想从URL中获取参数的值,以便从机会中填充一些值,但它不起作用。我没有使用控制器。 这里是网址:从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> 

请,谁能帮助我? 感谢

回答

0

您可以使用下面的语法来从URL参数读取值

{!$CurrentPage.parameters.testParam} 
0

您可以设置使用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选项: 链接:?/顶点/ 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> 
` 
+0

谢谢,但我不想使用控制器扩展。 –

+0

添加Javascript选项到我上面的答案。 –