[SalesForce] apex:outputText remove LEFT

is there any possibility to use LEFT to remove first 5 characters of string? My records of UoM always have a first 5 chars as code, which I do not want o print out.


Best Answer

Two ways you could do this.

First, if this is data that you want in circumstances other than just this visualforce page, I'd suggest adding a formula field to the object and then just mapping to the new field. In this case, you are not duplicating data as you are simply driving the value off of the existing field. In your formula field use this formula:

RIGHT(line.SCMC__Supplier_Unit_of_Measure__c, LEN(line.SCMC__Supplier_Unit_of_Measure__c)-5)

Option two, if you don't need the value except in this instance, or (as it appears this is from a managed package) you don't have control over the object, you could just use the exact same formula in the binding for the output. Expressions support most functions in the Salesforce formula functionality. So like this:

<apex:outputText value="{!RIGHT(line.SCMC__Supplier_Unit_of_Measure__c, LEN(line.SCMC__Supplier_Unit_of_Measure__c)-5)}" /> 

Barring that, you could write something into an Apex controller, but with these options at your disposal, I don't know why you would.

Related Topic