Happy Business Starts Here

Custom Clone Quote Visualforce Redirect to ClonedQuote (ID)

Highlighted
Savvy Scholar

Custom Clone Quote Visualforce Redirect to ClonedQuote (ID)

Hi All, 

We have created a new action in Salesforce to create a custom clone quote by using the Out of the Box Zuora CloneQuote Methods provided.

Currently the quote is cloned correctly but
when the quote is cloned then the user is not navigated to the newly created quote but still views the original quote. We make use of an action, a Visual force and a controller extension with teh Zuora ClonedQuote() method. in the controller I am not able to get the record id for the new cloned quote so that we can redirect the user to the new cloned quote.

Resources referenced: 

https://knowledgecenter.zuora.com/CPQ/I_Development_Resources/C_Component_Library/C_Global_Classes/Q...
https://community.zuora.com/t5/Zuora-CPQ/Question-on-Clone-Quote/td-p/26068

 

Controller Snippet:


clonedQuote.buildAndSave();
System.debug('This is the clonedQuote: ' + clonedQuote);

}

PageReference pageRef = new PageReference('/'+qt.Id); // I think the clonedQuote Id(clonedQuote.Id) needs to be here but then there is an error
//System.debug('clonedQuote PageReference is ' +ClonedQuote);
pageRef.setRedirect(true);
return pageRef; //Returns to the quote page

 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Savvy Scholar

Re: Custom Clone Quote Visualforce Redirect to ClonedQuote (ID)

Solution provided by the Support team 

  • Created a public instance for the Quote clonedSObject
  • Assigned the value from clonedQuote to the above instance.
  • then after passing the clonedSObject.Id to the PageReference, redirect functionality worked
public class CustomCloneQuoteExtension{

    public zqu__Quote__c qt { get; set; }   
    public Id Id { get; set; }
    public zqu__Quote__c clonedSObject ; // change 1

    //  constructor to get the Quote record
    public CustomCloneQuoteExtension(ApexPages.StandardController QuoteStandardController){
        // public CustomCloneQuoteExtension(ApexPages.StandardController controller) {
        qt =  (zqu__Quote__c) QuoteStandardController.getRecord();
        Id = qt.Id;
        System.debug('The original quote id: ' + qt.Id);
    }
    //Method that can is called from the Visual Force page action attribute
    public PageReference CloneQuote() {
        //build your code logic here

        //Load an existing quote
        zqu.Quote existingQuote = zqu.Quote.getInstance(qt.Id);
        System.debug('ExistingQuote: ' + existingQuote);

        //populate the clone options
        zqu.CloneQuoteOptions options = new zqu.CloneQuoteOptions();
        System.debug('CloneQuoteOptions: ' + options);
        options.shouldCloneProducts = true;

        //clone the quote
        zqu.QuoteCloneResponse cloneResponse = existingQuote.cloneQuote(options);
        System.debug('CloneResponse: ' + cloneResponse);

        //save the cloned quote
        if (cloneResponse.isSuccess) {
            zqu.Quote clonedQuote = cloneResponse.clonedQuote;

            clonedQuote.buildAndSave();
            clonedSObject  = clonedQuote.getSObject(); // Change 2

        }

        return new PageReference('/' + clonedSObject.Id);  // change 3  
    } 
}

 

View solution in original post

2 REPLIES 2
Highlighted
Savvy Scholar

Re: Custom Clone Quote Visualforce Redirect to ClonedQuote (ID)

Solution provided by the Support team 

  • Created a public instance for the Quote clonedSObject
  • Assigned the value from clonedQuote to the above instance.
  • then after passing the clonedSObject.Id to the PageReference, redirect functionality worked
public class CustomCloneQuoteExtension{

    public zqu__Quote__c qt { get; set; }   
    public Id Id { get; set; }
    public zqu__Quote__c clonedSObject ; // change 1

    //  constructor to get the Quote record
    public CustomCloneQuoteExtension(ApexPages.StandardController QuoteStandardController){
        // public CustomCloneQuoteExtension(ApexPages.StandardController controller) {
        qt =  (zqu__Quote__c) QuoteStandardController.getRecord();
        Id = qt.Id;
        System.debug('The original quote id: ' + qt.Id);
    }
    //Method that can is called from the Visual Force page action attribute
    public PageReference CloneQuote() {
        //build your code logic here

        //Load an existing quote
        zqu.Quote existingQuote = zqu.Quote.getInstance(qt.Id);
        System.debug('ExistingQuote: ' + existingQuote);

        //populate the clone options
        zqu.CloneQuoteOptions options = new zqu.CloneQuoteOptions();
        System.debug('CloneQuoteOptions: ' + options);
        options.shouldCloneProducts = true;

        //clone the quote
        zqu.QuoteCloneResponse cloneResponse = existingQuote.cloneQuote(options);
        System.debug('CloneResponse: ' + cloneResponse);

        //save the cloned quote
        if (cloneResponse.isSuccess) {
            zqu.Quote clonedQuote = cloneResponse.clonedQuote;

            clonedQuote.buildAndSave();
            clonedSObject  = clonedQuote.getSObject(); // Change 2

        }

        return new PageReference('/' + clonedSObject.Id);  // change 3  
    } 
}

 

View solution in original post

Highlighted
Community Manager

Re: Custom Clone Quote Visualforce Redirect to ClonedQuote (ID)

Thanks for sharing the solution with the community @AneskeMeiring ! 


Lana Lee | Senior Community Manager and Strategist
"A little consideration, a little thought for others, makes all the difference." —A. A. Milne