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
RiapatelRiapatel 

VF page

Hi,
I created a visual force page and controller class.In that vf page  i saved a record. How do i show the same record which i saved now in next vf page after clicking save button ? can i do that using recordid?

Best Answer chosen by Riapatel
Amit Chaudhary 8Amit Chaudhary 8
Option 1:-
redirect to new VF page with record ID and use <apex:Detail tag to show all detail
public class TaskoneCTR {
    public string Pname1{get;set;}
    
     public PageReference MYsave() {
     position__c ps1 = new position__c();
            ps1.name=Pname1;
            Insert ps1;
     return new PageReference('/apex/myPage'+ps1.id);
     // return new PageReference('/'+ps1.id); // use this line if you dnt want to create new VF page for View
     }
     
     
}

For example, if 001D000000IRt53 is the account ID, the resulting URL should be: https://Salesforce_instance/apex/myPage?id=001D000000IRt53
 
<apex:page standardController="position__c">
   <apex:detail subject="{!position__c.Name}" relatedList="false" title="false"/> 
</apex:page>
Option 2:-
User below to show record detail
PageReference accdetailPage = acc.view();

Related link for u:-
http://salesforce.stackexchange.com/questions/4798/how-does-apexdetail-work-can-we-show-layout-for-a-new-record
https://www.salesforce.com/docs/developer/pages/Content/pages_quick_start_tabs.htm

Please let us know if this solution will help you.
 

All Answers

RiapatelRiapatel
I am new to SF development. Here is my code for controller. once i save the record i go to next VF page with this code but how do i show the record i saved in next page using recordid?


public class TaskoneCTR {
    public string Pname1{get;set;}
    
     public PageReference MYsave() {
     position__c ps1 = new position__c();
            ps1.name=Pname1;
            Insert ps1;
     return page.VFtasktwo;
     }
     
     
}
Amit Chaudhary 8Amit Chaudhary 8
Option 1:-
redirect to new VF page with record ID and use <apex:Detail tag to show all detail
public class TaskoneCTR {
    public string Pname1{get;set;}
    
     public PageReference MYsave() {
     position__c ps1 = new position__c();
            ps1.name=Pname1;
            Insert ps1;
     return new PageReference('/apex/myPage'+ps1.id);
     // return new PageReference('/'+ps1.id); // use this line if you dnt want to create new VF page for View
     }
     
     
}

For example, if 001D000000IRt53 is the account ID, the resulting URL should be: https://Salesforce_instance/apex/myPage?id=001D000000IRt53
 
<apex:page standardController="position__c">
   <apex:detail subject="{!position__c.Name}" relatedList="false" title="false"/> 
</apex:page>
Option 2:-
User below to show record detail
PageReference accdetailPage = acc.view();

Related link for u:-
http://salesforce.stackexchange.com/questions/4798/how-does-apexdetail-work-can-we-show-layout-for-a-new-record
https://www.salesforce.com/docs/developer/pages/Content/pages_quick_start_tabs.htm

Please let us know if this solution will help you.
 
This was selected as the best answer
Prabhat Kumar12Prabhat Kumar12
You can you PageReference to do this.
 
PageReference rdr = new PageReference('VFtasktwo/' +ps1.id); 
rdr.setRedirect(true);
 return rdr;
Mark this as answer if it works for you.
 
RiapatelRiapatel
Thanks Amit and Prabhat. Amit, I tried the option 1 and it worked. thanks.