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
vamsi krishna 106vamsi krishna 106 

page reference is not working


pagereference parentpage=new pagereference('/'+id);
i tried like above and below
 
return new ApexPages.StandardController(oldtisdetails).view();

both are not working please help me..
charforcecharforce
Both options look fine. I assume you are returning the parentPage object reference in option 1. Do you get an error message? What exactly do you mean when you say both options don't work?

Below is an example of both options which work fine. 

<apex:page controller="mySecondController" tabStyle="Account">
    <apex:sectionHeader title="New Account Edit Page" />
    <apex:form>
        <apex:pageBlock title="Create a New Account">
            <apex:pageBlockButtons location="bottom">
                <apex:commandButton action="{!save}" value="Save"/>
            </apex:pageBlockButtons>
            <apex:pageBlockSection title="Account Information">
                <apex:inputField id="accountName" value="{!account.name}"/>
                <apex:inputField id="accountSite" value="{!account.site}"/>
            </apex:pageBlockSection>
       </apex:pageBlock>
    </apex:form>
</apex:page>

public class mySecondController {
    Account account;

    public Account getAccount() {
        if(account == null) account = new Account();
        return account;
    }

    public PageReference save() {
        // Add the account to the database. 
        insert account;

        // option 1
        return new PageReference('/' + account.Id);
        // option 2 
        //return new ApexPages.StandardController(account).view();
       
    }
}

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_system_pagereference.htm
Amit Chaudhary 8Amit Chaudhary 8
Please try like below code.
return  new pagereference('/'+id);
Please let us know if this will help you
 
David OvellaDavid Ovella
 Hello vamsi
can you try these codes

Opcion 1
        PageReference pr=new PageReference('/'+olddetailsId);
        pr.setRedirect(true);
        return pr;    

Opcion 2
        PageReference OldDetailsPage = new ApexPages.StandardController(oldtisdetails).view();
        OldDetailsPage.setRedirect(true);
        return OldDetails;
jyothsna reddy 5jyothsna reddy 5
Hi Vamsi,

Please try this below sample code
Pagereference pr=new pagereference('/'+a.id);
return pr;
Here "a" is object handler.

Regards,
Jyothsna D