+ Start a Discussion
TehNrdTehNrd 

How to redirect from VF page to Add Products and back

I'm building a pricing tool and from this tool users can add products. I really don't want to reinvent the functionality of adding products that already exists. I am trying to create a button that sends the user to the out of the box add products functionality and then when completed it should return the user to the visual force page.

I am failing big time. The code below is what I have and it appears to be populating the retURL parameter correctly but this doesn't work at all. If you hit cancel in the add products tool or save it always returns you to the opp, not the visualforce page which is what I want.

Does anyone know of other URL parameters I need to add to make this work? Is it even possible?

Page:
<apex:page controller="addProductsRedirect">
<apex:outputField value="{!opp.Id}"/>-
<apex:outputField value="{!opp.Name}"/>

<apex:form >
<apex:commandLink value="Add Product" action="{!addProduct}">
<apex:param name="addProductsURL" value="{!URLFOR($Action.OpportunityLineItem.AddProduct)}" assignTo="{!addProductsURL}"/>
</apex:commandLink>
</apex:form>
{!URLFOR($Action.OpportunityLineItem.AddProduct)}
</apex:page>



Controller:
public class addProductsRedirect {

Opportunity opp;
public String addProductsURL {get; set;}

public Opportunity getOpp(){
if(opp == null){
opp = [select Id, Name from Opportunity limit 1];
}
return opp;
}

public PageReference addProduct(){
PageReference p = new PageReference(addProductsURL );
p.getParameters().put('addTo',opp.Id);
p.setRedirect(true);
return p;
}
}

Much thanks,

Jason

Message Edited by TehNrd on 12-15-2009 12:25 PM
michaelforcemichaelforce

You might be able to use some sneaky / hacky AJAX on the Opportunity... inline s-control (quick before they go away :smileytongue: ) to check the history to see where the user came from and if they were on your visualforce page then redirect the browser to the desired page.

 

Not ideal, but the only thing I can think of.

 

I wish that you could use triggers to send a user to a specific PageReference.

TehNrdTehNrd

Ya.....I've got one of these hidden redirects already with an inline VF page for something else and I really don't want to add blind actions. Users are easily confused when they start getting sent all over the place automatically.

 

The user's do access this tool from the opportunity so they would only need to click a button to get back but it is the little things like this that make your app seem like it's not finished.

 

If there is no way to make this work I'll either leave it as is or build a very lightweight Add Products functionality.

S_LieS_Lie

Just create add product functionality, I did the same way :)

michaelforcemichaelforce

Is it possible to have an iframe in a visualforce page that would display the product entry page?  It would be tough to get it centered just right so that the header and sidebar are hidden... but that could be pretty cool.  The 'wrapper' visualforce page can then poll to see when the products are actually added (since you can't have the frame and the page talk directly) and then redirect or any other action when products are detected.

 

Kind of wacky, I know... but it might be wacky enough to work :-).

WesNolte__cWesNolte__c

Hey Mr TehNrd

 

There should be a retURL parameter that will work automatically. The key's case sensitive, so you might also want to try 'retUrl':

 

p.getParameters().put('retURL',ApexPages.CurrentPage().getUrl());

 

You'll also have to urlencode the retURL value.

 

Wes

 

 

TehNrdTehNrd

S_Lie wrote:

Just create add product functionality, I did the same way :)


Rebuilding something that already exists would be my last option.



michaelforce wrote:

The 'wrapper' visualforce page can then poll to see when the products are actually added


This is not a bad idea but there could be a five second delay. It doesn't seem like much but I could see that confusing some users. What I may be able to do is open a popup type window that has the iframe for the add products functionality and then have a close button for this popup. When the close button is clicked I could then query for the new products.

The weird thing about this is that in the iframe, after the products are added, they will see the opportunity detail page, header, and sidebar in the iframe, in the VF page which has its own side bar and header.

 

Still debating on what to do but leaning towards doing nothing and letting the user get dumped back at the opportunity.

Message Edited by TehNrd on 12-16-2009 10:41 AM
TehNrdTehNrd

weznolte wrote:

Hey Mr TehNrd

 

There should be a retURL parameter that will work automatically. The key's case sensitive, so you might also want to try 'retUrl':

 

p.getParameters().put('retURL',ApexPages.CurrentPage().getUrl());

 

You'll also have to urlencode the retURL value.

 

Wes

 


Negatron. For some reason this retURL does not work with the standard Add Products functionality.

michaelforcemichaelforce

"Negatron"..haha...

 

Yeah, the only time the retURL would get used if if the user hits "Cancel"... saving the products always ignores the retURL.

TehNrdTehNrd
Errrr.... I'm just going to build a very lightweight add products functionality. It will give the best end user experience.
WesNolte__cWesNolte__c
Negatron indeed :) Looking at my live Org I realised I've built custom funcationality for exactly this reason earlier this year :/ **bleep** brain's getting forgetful.
TehNrdTehNrd
Fric! Salesforce hates me.

System.Exception: pricebookentry is not searchable

 

Tried to use SOSL but no go. Anyone know how to use wide cards with the SOQL LIKE condition?
TehNrdTehNrd

Got it. Percent symbol, not asterisks.

http://community.salesforce.com/sforce/board/message?board.id=apex&message.id=17701&query.id=362605#M17701

Bard09Bard09

weznolte/TehNrd, would either of you mind sharing your code for recreating the Add Products page?

 

Our organization is frustrated with the inability to customize the Multi-Line Item List page after the Add Products screen (such as the arbitrary fixed-width text fields and inability to apply conditional filters), and from what I've researched, the only way to customize the logic of that page is to recreate the Add Products page before it.

 

I'm a decent VF coder, but not a virtuoso, so am a little concerned that any replacement I make for it will be far inferior to the 'stock' Add Products screen.

 

If you wouldn't mind sharing I'm sure others would benefit from your experience in the area, as well :)

 

[EDIT: Just stumbled on Jeff Douglas' demo for a very similar feature, here: http://blog.jeffdouglas.com/2009/01/13/apex-search-with-checkbox-results/.  I'm pretty sure I can leverage this into what I need.  It doesn't have all the nice filter options that the default Add Products solution has, but it should work for us in a pinch]

pierreeymard@saaspointpierreeymard@saaspoint

Hi, 

Reading the end parts of this thread: if you want to redirect after Save, you can use saveURL , as in 

...&saveURL=%2F{!whateverID}

 

Pierre Eymard

pierre.eymard@saaspoint.com

Saaspoint

London, UK