+ Start a Discussion
Arup SarkarArup Sarkar 

Formatting data in Apex and returning to VF

Hi :

 

I have a Apex controller which returns List<Task>. This object has 4 product columns which needs to be formatted in the visualforce page which is rendered as pdf. Here is the code for Apex class followed by Visualforce page.

 

How can I format the 4 product fields into a comma separated single field and return it to visual force, the reason being 

Product_Alts__c, Products_Equity__c, Products_Fixed_Income__c, Products_Multi_Asset__c will not always have values. So before returning I would like to format it, now number of records returned can be 1 or greater or 0 depending on the query condition.

 

 

I have not copied the entire code since it is long, but proper variable reference exist in the code.

public List<Task> CallReportData = new List<Task>();

    public List<Task> getCallReportData(){
    
            CallReportData = [select Id, OwnerId, AccountId, Activity_Type__c, Date__c, Location__c, CreatedById, 
                                Contacts__c,Employees__c,Description, Comments__c, Product_Alts__c, Products_Equity__c, 
                                Products_Fixed_Income__c, Products_Multi_Asset__c, Asset_Class_Formula__c 
                                from Task 
                                where (Date__c >= :From_Date and Date__c <= :To_Date)
                                and Type__c = 'Call Report'
                                order by Owner.Name, Date__c];

            return CallReportData;

    }

 

Visual force page.

 

<apex:page controller="GenerateCallReportController" renderAs="pdf">

    <apex:pageBlock >
        <apex:pageblockTable value="{!CallReportData}" var="task">


            <apex:column breakBefore="true" style="vertical-align:Top;height:20">
                <apex:outputText value="Products:" style="font-weight:bold; font-family:Tahoma; font-size:x-small; color:#002C52; width:10%; height:20px"/>
            </apex:column>            

            <apex:column value="{!task.Product_Alts__c}" style="font-weight:normal; font-family:Tahoma; font-size:x-small; width:45%; height:20px"/>            
            <apex:column breakBefore="true" style="vertical-align:Top;height:20"/>
            <apex:column value="{!task.Products_Equity__c}" style="font-weight:normal; font-family:Tahoma; font-size:x-small; width:45%; height:20px"/>
            <apex:column breakBefore="true" style="vertical-align:Top;height:20"/>
            <apex:column value="{!task.Products_Fixed_Income__c}" style="font-weight:normal; font-family:Tahoma; font-size:x-small; width:45%; height:20px"/>
            <apex:column breakBefore="true" style="vertical-align:Top;height:20"/>
            <apex:column value="{!task.Products_Multi_Asset__c}" style="font-weight:normal; font-family:Tahoma; font-size:x-small; width:45%; height:20px"/>








        </apex:pageblockTable>
    </apex:pageBlock>
</apex:page>

 

Best Answer chosen by Admin (Salesforce Developers) 
Arup SarkarArup Sarkar

Bob:

 

I have been able to achieve what you suggested as follows:

 

<apex:column value="{!task.Product_Alts__c},{!task.Products_Equity__c},{!task.Products_Multi_Asset__c},{!task.Products_Fixed_Income__c}" style="font-weight:normal; font-family:Tahoma; font-size:x-small; width:45%; height:20px"/>

 So far so good, only problem is that if there are no values even then commas exist. If somehow I can remove that it will be complete.

 

Regards,

Arup

All Answers

bob_buzzardbob_buzzard

Is there any reason why you can't do this client side, i.e. simply render the fields with commas in between?  If not, I think you'll need to create a wrapper class that contains a task and the concatenated string and returns a list of those for the page to render.

 

 

 

 

Arup SarkarArup Sarkar

Bob:

 

Thanks for your reply, I do not have any problem doing it on the client side, but I do not know how to format it. For example, if I do this I am getting an error

 

            <apex:column value="{!task.Product_Alts__c + !task.Products_Equity__c}" style="font-weight:normal; font-family:Tahoma; font-size:x-small; width:45%; height:20px"/>            

 

Error:

=======

Error: Incorrect parameter for function 'not()'. Expected Boolean, received Text

 

if you could let me know the exact syntax it would be great.

 

Regards,

Arup

Arup SarkarArup Sarkar

Bob:

 

I have been able to achieve what you suggested as follows:

 

<apex:column value="{!task.Product_Alts__c},{!task.Products_Equity__c},{!task.Products_Multi_Asset__c},{!task.Products_Fixed_Income__c}" style="font-weight:normal; font-family:Tahoma; font-size:x-small; width:45%; height:20px"/>

 So far so good, only problem is that if there are no values even then commas exist. If somehow I can remove that it will be complete.

 

Regards,

Arup

This was selected as the best answer
bob_buzzardbob_buzzard

You'll need to use outputpanels and only render the field and commas if there are values present.