Find your content:

Search form

You are here

Fill a field with the owner of a record shown in a visualforce page

 
Share

I'm new in salesforce and i'm freaking out with this problem: I have a visualforce page that dinamically shows me a record of a custom object. Now, in this page, I have a button that redirect me in a new visualforce page in which I a have a form. I have to fill a field of this form with the owner of the record shown in the previous page. How can I resolve this problem?


Attribution to: user7750

Possible Suggestion/Solution #1

Without any code it's difficult to give a specific answer, but as a general solution you can use URL parameters to pass data between Visualforce pages, such as in your example.

Assuming you are using a method in your first page to redirect to the second page, e.g.

public with sharing class Page1Controller
{
    public PageReference saveAndRedirect()
    {
        // ... Do some logic

        PageRef pageRef = Page.MySecondPage;
        pageRef.setRedirect(true);
        return pageRef;
    }
}

You can change this method add parameters to the page reference for your second page, like so:

public with sharing class Page1Controller
{
    public PageReference saveAndRedirect()
    {
        // ... Do some logic

        PageRef pageRef = Page.MySecondPage;
        pageRef.setRedirect(true);

        pageRef.getParameters().put('ownerid', yourowneridhere);

        return pageRef;
    }
}

Then in your controller for you second page you can retrieve these parameters and use them:

public with sharing class Page2Controller
{
    public Page2Controller()
    {
        Id ownerId = ApexPages.currentPage().getParameters().get('ownerid');
        // ... Do something with the retrived ID
        // e.g. pre-populate a field in one of your objects, or query for more information
    }
}

Attribution to: Alex Tennant
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/32045

My Block Status

My Block Content