Salesforce.com really does a great job of always pushing their User Interface to the next level either by implementing Ideas from the IdeaExchange or by giving us cool enhancements we never knew we needed. For whatever reason, however, the screens used to add Products to Opportunities are somewhat outdated (in my opinion). The standard pages get the job done… especially if you have very few products, or your Opportunities only require a single Product, but if you need to do more it can be a lot of clicks.
So in short, I came up with my own Visualforce Page for adding Products to Opportunities which allows a user to Search, Add, Remove, and Edit all in one screen.
The upper section is our “Shopping Cart” so to speak, and the bottom section is where we search for products and hit “Select” to add to the cart. Note there is no “Search” button… when the user stops typing for more than a second it automatically searches and refreshes the results.
2 Visualforce Pages
3 Apex Classes
For this recipe I am giving you a package you can install to get the code in your org (yippee!). The first step obviously is to install the package making sure that you grant access to all profiles that manage products on opps. You will want to select the option to ignore test failures. The package DOES contain a test class… but depending on a lot of factors it may or may not run successfully in your org right off the bat.
Next you need to go to: Setup -> Customize -> Opportunities -> Opportunity Products -> Buttons and Links. You need to Override three of the Standard Buttons with our new pages. Make your setup match the following:
Now you can go ahead and try it out. Go to an Opportunity and start working with the Products related list… it’s fun for the whole family.
Here are some important things to note:
- The code will work whether or not you have multi-currency turned on.
- The pages will display object and field names as you have them labeled (e.g. if you relabeled “Products” to “Items” the page will display “Selected Items” instead of “Selected Products”)
- If you have default pricing for your products it will be defaulted into the ‘Sales Price’ when added to the cart, but will be editable (just as you were probably expecting).
- If you have custom fields on “Opportunity Products” you may need to modify the code to capture them in the “Selected Products” section.
- By default, the search looks in the “Name” and “Description” fields of Products. You will need to customize the extension in order to search additional fields.
- As mentioned earlier, the test class included should be looked at as a starting point for you. Even if it runs after installation, I recommend you edit and augment it in order to truly cover all the bases in the context of your org. For example, I query my test data because it was the best shot at having the class run in your org first try… but best practices tells you to create your test data.
- This recipe doesn’t address schedules (although that can be a bit painful too… maybe a good idea for a future recipe). If you use this recipe, users would still click the line item and create schedules the same way they do today.
- If salesforce.com changes the URL for their standard pricebook selection screen, this code will need to be updated to continue to function.
- disclaimer: This is code I am sharing with the cool people of the salesforce community. This is not an AppExchange app, and hence there is no guarantee it will work properly. I do not officially provide support for this code, although I will do my best to answer questions because I love you.
Alright people, have at it, and let me know what you think… even better, let me know how you modify the code to make it even ‘snazzier’!