0

I created a custom button(URL) on Opportunity object, that redirects me in a visualforce page to create a new Task. I am trying to get the values of parameters from URL to per-populate some values from opportunity, but it is not working. I am not using controllers. Here is the URL :

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

Here is my visualforce page:

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

Please, can anyone help me? Thanks

ana ajazi
  • 1
  • 3

2 Answers2

0

You can use below syntax to read value from URL parameter

{!$CurrentPage.parameters.testParam}  
Yagnesh Agola
  • 4,556
  • 6
  • 37
  • 50
0

You can set values using URL hacking (which is what you are trying to do?), but this is unsecure/patchy and not recommended. Salesforce can stop supporting this functionality anytime.

I suggest you create a controller extension, read the page parameter in it and set the fields.

In constructor of extension class you can set fields as

`

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 Option: Link : /apex/TestVF?whatID=001i000000IsaJu&whatName=Infosys

Page:

`
    <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>
`
Arun Kumar
  • 382
  • 1
  • 7