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
RbnRbn 

Prepopulating Data from one vf page to another page

Hi,

 

I have a page which retrieves records of a Custom object.

 

Now when i click on the edit hyperlink the data should get pre populated to the next page.

Thanks in Advance

souvik9086souvik9086

What is the exact requirement?

 

You shared that when you click edit then it will go to another page. Is there any special reason for that? You can made it in same page by using rendering property.

 

But if you still want to do that in another page then you can use same controller for both the pages and use that object variable in the outputfield in first page and inputfield in second page.

 

If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.

Thanks

RbnRbn

tahnks for the Quick Reply.

 

For ur understanding i am posting the below code:

 

1 st vf PAge:

<apex:page showHeader="false" controller="hometab">

  <apex:form >
            <apex:pageBlock title="Shared Activities">
                <apex:pageBlockTable value="{!tasks}" var="tas" id="filteredtasks">
                
              <apex:column >
                <apex:facet name="header">Action</apex:facet>
                <a href="/apex/edittas?id={!tas.Id}" target="_blank" style="font-weight:bold">Edit</a> |
                <a href="/{!tas.Id}/e" target="_blank" style="font-weight:bold">Delete</a>
                
                </apex:column>
                       
               
                 <apex:column >
                    <apex:facet name="header">
                    <apex:outputPanel layout="inline">
                        subject
                    </apex:outputPanel>
                     
                    </apex:facet>
                      <apex:outputText value="{!tas.Subject__c}"> </apex:outputText>
                </apex:column>
                <apex:column >
                    <apex:facet name="header">
                    <apex:outputPanel layout="inline">
                        Name
                    </apex:outputPanel>
                    </apex:facet> <apex:outputText value="{!tas.name}"> </apex:outputText>
                             </apex:pageBlockTable>
            </apex:pageBlock>
  </apex:form>
  
</apex:page>



Controller::

public class hometab {
public Task tasku{get;set;}
    public hometab(ApexPages.StandardController controller) {

      tasku = new Task();

    }




    public hometab()
    {
    
    }

  Public list<Task_Object__c> gettasks(){
     List<Task_Object__c> t=new list<Task_Object__c>([SELECT Id, Name, Subject__c, Type__c, Description__c, Status__c, Priority__c, Phone__c, Email__c, Resources__c, Reason__c, What__c, Who__c, Standard_Task__c, ActivityDate__c FROM Task_Object__c ]);
    return t;
  }
  
}

 When i click on edit it navigates me to the below Page:

<apex:page standardController="Task_Object__c" extensions="tascon">
 <apex:form > 

        <apex:messages />
        <apex:pageBlock title="Task Edit">
         <apex:pageBlockButtons >
                <apex:commandButton value="Save"  />
                      </apex:pageBlockButtons>  
            
              <apex:pageblockSection title="Task Information" id="info">
      

                   <apex:inputfield value="{!tas.OwnerId}"/> 
                   <apex:inputfield value="{!tas.WhatId}" /> 
                    <apex:inputfield value="{!tas.Subject}" /> 
 
   
</apex:pageBlock>
</apex:form>
</apex:page>

Controller:

public with sharing class tascon {

       string st;
    public Task tas{get;set;}
    public tascon (ApexPages.StandardController controller) {
   

    st=System.currentPagereference().getParameters().get('id');
        System.debug('@@@@@@@@@3456'+st);
        tas = new Task(); 
   }
  
   Task_Object__c tasob = new  Task_Object__c ();
   public pagereference getdetails(){
   tasob = [SELECT Id, Name, Subject__c, Type__c,Assained_To__c where id=:st];
      {
  tas.OwnerId = tasob.Assained_To__c;
   }
return null;
}
}

 

souvik9086souvik9086

Do it like this

 

2nd Controller

 

public with sharing class tascon {

string st;

public Task tas{get;set;}
public Task_Object__c tasob = new Task_Object__c ();
public tascon (ApexPages.StandardController controller) {

st=System.currentPagereference().getParameters().get('id');
System.debug('@@@@@@@@@3456'+st);
tas = new Task();
tasob = [SELECT Id, Name, Subject__c, Type__c,Assained_To__c FROM Task_Object__c where id=:st];
tas.OwnerId = tasob.Assained_To__c;
tas.Subject = tasob.Subject__c;
tas.WhatId = tasob.YourField;
}

public pagereference getdetails(){
//Do something
return null;
}
}

 

If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.

Thanks

 

 

RbnRbn

Thanks Souvik...i gt it..by assigning inside the Constructor.

 

But now after saving ..i am able to redirect to the Home Page but the modification which i have done after editing is not getting reflected when i click on Save.

 

below is my Code::

  public pagereference redirect(){
   Task_Object__c savtas = (Task_Object__c ) con.getRecord();
    update savtas ;
    String id = ApexPages.CurrentPage().getparameters().get('id');
     PageReference tassav = new PageReference('https://cs17.salesforce.com/home/home.jsp');
    tassav .setRedirect(true);
    return tassav ;
}

 

souvik9086souvik9086

Can you give your recent controller and vf page code for the edit page. In the 2nd page you are displaying task fields there. But where are you updating the task in the database. i found from your code that you are updating Task_object data but where are you updating task data to get reflected?

RbnRbn

Hi Souvik,

 

My latest Controller::

 

public with sharing class tascon {
ApexPages.StandardController con;

       string st;
    public Task tas{get;set;}
    public tascon (ApexPages.StandardController controller) {
    st=System.currentPagereference().getParameters().get('id');
    con = controller;

      tas = new Task(); 
     Task_Object__c tasob = new  Task_Object__c ();
   tasob =[SELECT Id,Assained_To__c, Name, Subject__c, Type__c, task_template_Id__c,Owner__c,Description__c, Status__c, Priority__c, Phone__c, Email__c, Resources__c, Reason__c, What__c, Who__c, Standard_Task__c, ActivityDate__c FROM Task_Object__c where id=:st];
  System.debug('!!!!!!!!!!!!!!!!3456'+ tasob);
  tas.OwnerId = tasob.Assained_To__c;
  tas.Subject= tasob.Subject__c;
  tas.Type = tasob.Type__c;
  tas.Description = tasob.Description__c ;
  tas.Act_Type__c = tasob.Reason__c;
  tas.ActivityDate= tasob.ActivityDate__c ;
  tas.Owner__c= tasob.Owner__c;
   tas.TaskTemplateId__c= tasob.task_template_Id__c;
        
   }
  public pagereference redirect(){
   Task_Object__c savtas = (Task_Object__c ) con.getRecord();
    update savtas ;
    String id = ApexPages.CurrentPage().getparameters().get('id');
     PageReference tassav = new PageReference('https://cs17.salesforce.com/home/home.jsp');
    tassav .setRedirect(true);
    return tassav ;
}

  
  
  }
   
  /* public pagereference getdetails(){
   Task_Object__c tasob = new  Task_Object__c ();
   tasob = [SELECT Id, Name, Subject__c, Type__c,Assained_To__c, Description__c, Status__c, Standard_Task__c, ActivityDate__c FROM Task_Object__c where id=:st];
  System.debug('!!!!!!!!!!!!!!!!3456'+ tasob);
    {
  tas.OwnerId = tasob.Assained_To__c;
  tas.Description = tasob.Description__c ;
  }
return null;
}
}*/

 

souvik9086souvik9086

public pagereference redirect(){
Task_Object__c savtas = (Task_Object__c ) con.getRecord();
update savtas ;
String id = ApexPages.CurrentPage().getparameters().get('id');
PageReference tassav = new PageReference('https://cs17.salesforce.com/home/home.jsp');
tassav .setRedirect(true);
return tassav ;
}

 

You are updating task object here. But in page you are displaying task data, which is user changing in the vf page. But you are not updating task in the controller. How it can be reflected?