function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
JagadeesJagadees 

[Change owner] link in custom VF page on Leads

I'm trying to build [Change] link next to record owner name on the lead VF page so that the user can re-assign the leads. My lead VF page is a completely custom build page. I'm expecting this functionality to work as in Standard page ie., when the user clicks the [Change] link he/she should be taken to the change ownership page from where he/she should re-assign the lead and the retUrl should take him/her back to the custom page.

I have used the below piece of code found in this forum - 
<apex:outputLink value="{!URLFOR($Action.Lead.ChangeOwner,Lead.id)}">[Change]</apex:outputLink>

But it's not working as expected. When I add this code and tested by clicking the output link [Change] it asks me to log in again and gives me an error as - 
Stale Session Exception
The page you submitted was invalid for your session. Please try your action again. 

Can I get some help here? 
Best Answer chosen by Jagadees
Lokesh KumarLokesh Kumar
HI Steve,

Hope you are using Standard controller for Lead.

Please try the below code for changing the owner though visual force page.
 
<apex:page standardController="Lead">
    <apex:pageBlock title="Hello {!$User.FirstName}!" mode="maindetail" >
        <apex:form >
            <apex:pageBlockSection title="Greeting" columns="1">
                You are viewing the detail pages for: {!Lead.name}.
            </apex:pageBlockSection>
            <apex:pageBlockSection title="Case Information" columns="2" rendered="True" Id="CaseInfo" >
                    <apex:outputText label="Owner" escape="False" value="{!Lead.Owner.Name} [{!LINKTO('Change' ,'/' + LEFT(Lead.id,15) + '/a?retURL=' + URLFOR('/apex/' + $CurrentPage.Name, null, ['id'=Lead.id]), Lead.Id) }]" />
            </apex:pageBlockSection>
        </apex:form>
    </apex:pageBlock>
</apex:page>

let me know if this helps you.

Thanks
Lokesh

All Answers

Lokesh KumarLokesh Kumar
HI Steve,

Hope you are using Standard controller for Lead.

Please try the below code for changing the owner though visual force page.
 
<apex:page standardController="Lead">
    <apex:pageBlock title="Hello {!$User.FirstName}!" mode="maindetail" >
        <apex:form >
            <apex:pageBlockSection title="Greeting" columns="1">
                You are viewing the detail pages for: {!Lead.name}.
            </apex:pageBlockSection>
            <apex:pageBlockSection title="Case Information" columns="2" rendered="True" Id="CaseInfo" >
                    <apex:outputText label="Owner" escape="False" value="{!Lead.Owner.Name} [{!LINKTO('Change' ,'/' + LEFT(Lead.id,15) + '/a?retURL=' + URLFOR('/apex/' + $CurrentPage.Name, null, ['id'=Lead.id]), Lead.Id) }]" />
            </apex:pageBlockSection>
        </apex:form>
    </apex:pageBlock>
</apex:page>

let me know if this helps you.

Thanks
Lokesh
This was selected as the best answer
JagadeesJagadees
@Lokesh,

Thank you, buddy. This works cool :) 
Ramesh VaratharajRamesh Varatharaj
Steve, Lokesh have you tried using this link on VF in LUX? I am planning to use the same VF page on LUX, but change owner link does not seem to work. It opens another tab with error message page is not avaialble in LUX or mobile app