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
mustapha laouari 15mustapha laouari 15 

APEX redirect to Quote details page

Hi there,
i did a method supposed to redirct into Quote details page, but it doesnt couldyou help please.
the method is excuted success, but redirect doesn't work.
qid is the ID of the quote.

Many thanks
public PageReference redirectQ(id qid){
        System.debug('STARTING redirectQ: '+qid);
		quote q = [SELECT id, name FROM QUOTE WHERE id=:qid];
         System.debug('quote q: '+ q);
        PageReference QuotePage = new PageReference(qid);
        System.debug('QuotePage: ' + QuotePage);
        QuotePage.setRedirect(true);
        return QuotePage;
    }

 
Best Answer chosen by mustapha laouari 15
VivekShindeVivekShinde
Here's a catch! From the vf page, savePDF button is getting called but, this method is returning void. You need to either write the code of redirectQ method inside the savePDF method or simply call the redirectQ method as following with changing the return type from void to Pagereference of the savePDF method.
public Pagereference savePDF() {
    //Your existing logic
    return redirectQ(aid);
}

All Answers

VivekShindeVivekShinde
Instantiate the pagereference as:
PageReference quotePage = new PageReference('/'+qid);

 
mustapha laouari 15mustapha laouari 15
Hi, many thanks for your repply , betwwen my post i have tried this but it doesn't work, no sense.
has you can see i did a debug, to ensure the Qid is correct.
i extracted that qid from log, and when manually type the URL http://salesforce.../eedkn8df54df8
i can see the Quote details page.
strange, isn't it ?
VivekShindeVivekShinde
Can you post the visuaforce code from where this method is getting called? There could be issues with that code.
mustapha laouari 15mustapha laouari 15
sure, thanks forfollowing.
this is the VF page, which is quite simple, a Headband on top, with just a Save button, and uder that an iframe to another VF page (in charge to display the quote details)

when press the Save button, it launch the SavePDF in charge to store the Iframe content in PDFquote (in PDF format), idea is after that it shoud go back to the SObject Quote details which should contains the PDF document attached.
Everything ok, except the rediect.

the VF page :
<div>
           <apex:form > 
		<apex:pageBlock title="Document Preview">         
                <apex:pageBlockButtons >
                <apex:commandButton action="{! savePDF }" value="Save to Quote" />  
                    </apex:pageBlockButtons>
                       
         <div align="center">
             <apex:iframe src="apex/PDFredirect?id={!quote.id}" scrolling="true" height="1000px" width="50%"  />
         </div>
          
   		</apex:pageBlock>    
             </apex:form> 
     </div>

and the methods:
 
//Saves the PDF to the quote 
	public void savePDF(){
        id qid = ApexPages.currentPage().getParameters().get('Id');
        PageReference pageRef = new PageReference('/apex/NcQuote?id='+qid);
        Blob pdf = pageref.getContentAsPDF() ;
        System.debug('content:' + pdf);
        QuoteDocument doc = new QuoteDocument(Document=pdf, QuoteId=qid);
        System.debug('doc:' + doc);
        insert doc;	
        //comment the next line if no need to redirect to quote after PDF saved
        redirectQ(qid);
	}
    
    public PageReference redirectQ(id qid){
        System.debug('STARTING redirectQ: ' + qid);
        PageReference quotePage = new PageReference('/'+qid);
        quotePage.setRedirect(True);
        return quotePage;
    }

Thank you 
VivekShindeVivekShinde
Here's a catch! From the vf page, savePDF button is getting called but, this method is returning void. You need to either write the code of redirectQ method inside the savePDF method or simply call the redirectQ method as following with changing the return type from void to Pagereference of the savePDF method.
public Pagereference savePDF() {
    //Your existing logic
    return redirectQ(aid);
}
This was selected as the best answer
mustapha laouari 15mustapha laouari 15
I have tried by adding PageReference in pace of void into savePDF ... as you did , but the console says a problem.
so have moved the code of RedirectQ inside the savePDF method, and like this no error and it works fine !
MANY thanks for your assistance on this you are great !
VivekShindeVivekShinde
Glad that it worked!