You need to sign in to do that
Don't have an account?
Mimic "Action" column for Visualforce Opportunity Line Items
Hi,
I'm experimenting with putting my own Visualforce page in for Opportunity Line Items related list.
To start with, I have this:
<apex:page standardController="Opportunity"> <apex:pageBlock > <apex:pageBlockTable value="{!Opportunity.OpportunityLineItems}" var="oli"> <apex:column value="{!oli.Quantity}"/> <apex:column value="{!oli.ListPrice}"/> <apex:column value="{!oli.TotalPrice}"/> <apex:column value="{!oli.Sale_Type__c}"/> </apex:pageBlockTable> </apex:pageBlock> </apex:page>
I also want the first column "Action" in there as well, so that I can present the "Edit | Del" hyperlinks, slightly modified for my purposes, but still retaining the Salesforce.com look.
How do I put that into the markup above? I get the feeling that it's not something I can easily put into a pageBlockTable. If not, where (or how) do I put it in?
Also, my next problem is how to get the pageBlockButtons section in so that it refers to the OpportunityLineItems methods (whatever they actually are??? I can't seem to find standard controller methods anywhere in documentation).
Thanks!
I wish I could say I worked this out by using the excellent documentation but I didn't. I did search it high and low. I do wish the documentation was better arranged and more complete.
Anyway, here was my solution eventually.
<apex:page standardController="Opportunity"> <apex:form > <apex:pageBlock > <apex:pageBlockButtons location="top" > <apex:commandButton action="{!URLFOR($Action.OpportunityLineItem.AddProduct, Id)}" value="Add Product" /> <apex:commandButton action="{!URLFOR($Action.OpportunityLineItem.EditAllProduct, Id)}" value="Edit All" /> <apex:commandButton action="{!URLFOR($Action.OpportunityLineItem.ChoosePriceBook, Id)}" value="Choose Price Book" /> <apex:commandButton action="{!URLFOR($Action.OpportunityLineItem.Sort, Id)}" value="Sort" /> </apex:pageBlockButtons> <apex:pageBlockTable value="{!Opportunity.OpportunityLineItems}" var="oli"> <apex:column headerValue="Action"> <b><apex:outputLink value="{!URLFOR($Action.OpportunityLineItem.Edit, oli.Id)}">Edit</apex:outputLink></b> | <b><apex:outputLink rendered="{!oli.Renewal_Line_Item__c != true}" value="{!URLFOR($Action.OpportunityLineItem.Delete, oli.Id)}">Del</apex:outputLink></b> </apex:column> <apex:column headerValue="Product"> <apex:outputLink value="{!URLFOR( $Action.Product2.View ,oli.PricebookEntry.Product2Id)}">{!oli.PricebookEntry.Name}</apex:outputLink> </apex:column> <apex:column value="{!oli.Quantity}"/> <apex:column value="{!oli.ListPrice}"/> <apex:column value="{!oli.UnitPrice}"/> <apex:column value="{!oli.TotalPrice}"/> <apex:column value="{!oli.Sale_Type__c}"/> </apex:pageBlockTable> </apex:pageBlock> </apex:form> </apex:page>
All Answers
I wish I could say I worked this out by using the excellent documentation but I didn't. I did search it high and low. I do wish the documentation was better arranged and more complete.
Anyway, here was my solution eventually.
<apex:page standardController="Opportunity"> <apex:form > <apex:pageBlock > <apex:pageBlockButtons location="top" > <apex:commandButton action="{!URLFOR($Action.OpportunityLineItem.AddProduct, Id)}" value="Add Product" /> <apex:commandButton action="{!URLFOR($Action.OpportunityLineItem.EditAllProduct, Id)}" value="Edit All" /> <apex:commandButton action="{!URLFOR($Action.OpportunityLineItem.ChoosePriceBook, Id)}" value="Choose Price Book" /> <apex:commandButton action="{!URLFOR($Action.OpportunityLineItem.Sort, Id)}" value="Sort" /> </apex:pageBlockButtons> <apex:pageBlockTable value="{!Opportunity.OpportunityLineItems}" var="oli"> <apex:column headerValue="Action"> <b><apex:outputLink value="{!URLFOR($Action.OpportunityLineItem.Edit, oli.Id)}">Edit</apex:outputLink></b> | <b><apex:outputLink rendered="{!oli.Renewal_Line_Item__c != true}" value="{!URLFOR($Action.OpportunityLineItem.Delete, oli.Id)}">Del</apex:outputLink></b> </apex:column> <apex:column headerValue="Product"> <apex:outputLink value="{!URLFOR( $Action.Product2.View ,oli.PricebookEntry.Product2Id)}">{!oli.PricebookEntry.Name}</apex:outputLink> </apex:column> <apex:column value="{!oli.Quantity}"/> <apex:column value="{!oli.ListPrice}"/> <apex:column value="{!oli.UnitPrice}"/> <apex:column value="{!oli.TotalPrice}"/> <apex:column value="{!oli.Sale_Type__c}"/> </apex:pageBlockTable> </apex:pageBlock> </apex:form> </apex:page>
Here's why I said what I said earlier about documentation:
Searching "URLFOR" in the Force.com Apex Code Language Reference, Spring '09 returns a "No Topics Found" message.
This is just one example of many that I've come across since I started at all this a few months ago.
URLFOR in the VisualForce documentation does not document the arguments for actions. There are no bits of sample code. I've struggled to learn how to use it, from bits of code in the forums that demonstrate use cases not hinted at by the VF guide.
It would be great if Salesforce would open up the docs to allow us to post comments. That way we could collectively improve the code, adding what we learn.
RDN, thanks for posting this. Doesn't the delete link, though, immediately delete, rather than demanding a confirmation like the action column does?
And then unceremoniously dump user into the Opportunity tab, rather than returning to the referring page, as an Action Column would?