Play Games

Search This Blog

Wednesday, December 14, 2016

How to change the column name of related lookup fields of an object in a report in salesforce

Problem: An opportunity report is created using custom report type.
When we are displaying Billing City of Account object in report,its column name is showing as "Account Name: Billing City" as shown in the image below.

We need to change that column name from "Account Name: Billing City" to "Billing City".
Solution : We can change the column names from the edit layout of custom report type created.
Steps :
1) Go to the custom report type created  from setup --> Create --> Report Types.
Click on the label of that particular report type.A screen will appear as shown in the image below.

2) Click on the "Edit Layout" button. The layout will be opened as shown in the image below.


3) Search the column in the layout whose name to be changed.For example "Billing City" as shown in image below.

4)Double click on that particular field,A popup window will be opened as shown in the image below

Now you can change the name in "Display As" column as Shown in the image below.

Click "ok" after changing column names and then save the layout.
Now you can refresh the report and observe that the column names are changed...
Enjoy...

How to display related lookup fields of an object in report Salesforce

Problem : In order to display a report on opportunities,A custom report type "Opportunity Report Type" is created.While creating the report with this custom report type, we were unable to display fields of account record (lookup)which is associated with this opportunity.
Solution : We need to add all the related lookup fields to the custom report type layout.
Steps :
1) Go to the custom report type created  from setup --> Create --> Report Types.
Click on the label of that particular report type.A screen will appear as shown in the image below.

2) Click on the "Edit Layout" button. The layout will be opened as shown in the image below.

3) We can add the related lookup fields by using "Add fields related VIA Lookup" hyperlink which is present on the right side of the layout as shown in image below.

Select "Opportunity Fields" in view and click on "Add fields related VIA Lookup" hyperlink.A popup window opens as shown in image below

From here you can select all related fields which you want to show on report as shown in the image below.

Click on "Ok" after selecting fields and then save the layout by clicking "Save" button.
Now you can refresh the report...You will be able to see all the related fields in the palette.

Friday, December 9, 2016

How to give header and footer while generating pdf using visualforce page in salesforce

Example:
Apex Class :
public class GeneratePdf {
    public List<Account> accList {get;set;}
    public void generateReport() {
        accList = [select id,name,AccountSource,phone,industry from Account];
    }
}
Visualforce Page :
<apex:page renderAs="pdf" applyBodyTag="false" controller="GeneratePdf" action="{!generateReport}" applyHtmlTag="false" showHeader="false">
    <head>
        <style type="text/css" media="print">
            @page {                
                @top-center {                  
                    content: element(header);              
                }
                @bottom-left {
                    content: element(footer);
                }          
                margin-top: 100px;
                margin-bottom:80px;
            }                      

            div.header {              
                padding: 10px;            
                position: running(header);          
            }          
            div.footer {              
                display: block;            
                padding: 5px;              
                position: running(footer);        
            }                      

            .pagenumber:before {              
               content: counter(page);            
            }                      
            .pagecount:before {            
                content: counter(pages);          
            }                  
        </style>          
      </head>
     
      <div class="header">
          <div><center>List Of Accounts</center></div>
       </div>
       <div class="footer">
            <div>Page <span class="pagenumber"/> of <span class="pagecount"/></div>
      </div>
          <div class="content">
                <table cellspacing="0" cellpadding="5" width="100%" style="line-height:25px" border="1">
                 
                    <tr width="100%" style="border:1px">
                        <th>Account Name</th>
                        <th>AccountSource</th>
                        <th>Industry</th>
                        <th>Phone</th>
                        </tr>
                    <apex:repeat value="{!accList}" var="acc">
                        <tr width="100%" style="border:1px solid">
                            <td>{!acc.name}</td>
                            <td>{!acc.AccountSource} </td>
                            <td>{!acc.Industry} </td>
                            <td>{!acc.phone} </td>
                       
                        </tr>
                    </apex:repeat>
                </table>
          </div>

</apex:page>
Output:

How to get time from Datetime field in apex salesforce

Solution : Use field.format('h:mm a') to get time from DateTime field
Example:
Apex Class:
public class TimeController {
    public String sTime {get;set;}
    public String sTime1 {get;set;}
    public TimeController (){
        DateTime dtDateTime = system.now();
        sTime = dtDateTime.format('h:mm a');
        sTime1 = dtDateTime.format('h:mm');
    }
}
Visualforce Page :
<apex:page controller="TimeController">
Note The time is getting displayed :<b> {!sTime} </b><br/>
Note The time is getting displayed :<b>{!sTime1} </b>
</apex:page>
Output: