Find your content:

Search form

You are here

Save Products and Create New Quote from Custom Button in Visualforce

 
Share

I have included a piece of my apex class from a customized product selector. What I am trying to do is to create a custom button on my visualforce page and direct my users to the new quote they want to create from the products they have selected on the opportunity. When Input the code below I get this error:

Unable to Access Page The value of the "oppid" parameter contains a character that is not allowed or the value exceeds the maximum allowed length. Remove the character from the parameter value or reduce the value length and resubmit. If the error still persists, report it to our Customer Support team. Provide the URL of the page you were requesting as well as any other related information.

Is there another way I can get the products they select to save onto the opportunity and create a quote (go to the quote new edit page) all within the same button?

public PageReference onCreateQuote(){

    // If previously selected products are now removed, we need to delete them
    if(forDeletion.size()>0)
        delete(forDeletion);

    // Previously selected products may have new quantities and amounts, and we may have new products listed, so we use upsert here
    try{
        if(shoppingCart.size()>0)
            upsert(shoppingCart);
    }
    catch(Exception e){
        ApexPages.addMessages(e);
        return null;
    }  

    return new Pagereference('/0Q0/e?retURL=%2F{!Opportunity.Id}&oppid={!Opportunity.Id}');
}

Attribution to: NewbieDeveloper27

Possible Suggestion/Solution #1

This is where your problem is

return new Pagereference('/0Q0/e?retURL=%2F{!Opportunity.Id}&oppid={!Opportunity.Id}');

You have mixed up visual force and apex. {, ! are all Visualforce specific symbols, if you need to provide the oppty ID and retURL all you do is

//Get the current opportunity ID.

String Opportunity_ID = ApexPages.currentPage().getParameters().get('id')
return new Pagereference('/0Q0/e?retURL=%2F'+Opportunity_ID+'&oppid='+Opportunity_ID);

Attribution to: Rao
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/31775

My Block Status

My Block Content