Search This Blog

Friday, February 19, 2016

Comparable Interface in Salesforce

In order to sort the wrapper class records,we need to implement comparable interface.
Example:
Apex Class:
global class EmployeeSalary {    
    public List<Employee> employeeList {get;set;}  

    public EmployeeSalary() {
        EmployeeList = new List<Employee>();
        Employee emp1= new Employee ('Mahesh', 120000);
        EmployeeList.add(emp1);
       
        Employee emp2 = new Employee ('Arun', 30000);
        EmployeeList.add(emp2);
       
        Employee emp3 = new Employee ('Suresh', 32000);
        EmployeeList.add(emp3);
       
        Employee emp4 = new Employee ('Kailash', 32000);
        EmployeeList.add(emp4);
        EmployeeList.sort();
    }
   
    //wrapper class for Comparable Interface
    global class Employee implements Comparable {
        global String employeName{get;set;}  
        global Integer salary {get; set;}
       
        global Employee (String Name, Integer salary) {
            employeName = Name;
            this.salary = salary;
        }
       
        global Integer compareTo(Object ObjToCompare) {
            return employeName.CompareTo(((Employee)ObjToCompare).employeName);
        }
    }
}
Visualforce Page :
<apex:page showHeader="false" controller="EmployeeSalary" >
<apex:form >
    <apex:pageBlock >
        <apex:pageblockTable value="{!employeeList}" var="e">
            <apex:column value="{!e.employeName}"/>
            <apex:column value="{!e.salary}"/>
        </apex:pageblockTable>
    </apex:pageBlock>
</apex:form>    
</apex:page>
Output :

Thursday, February 4, 2016

How to delete an apex class or trigger from production org in salesforce

Steps :
Step 1:Open the sandbox org in force.com IDE(Eclipse).
Step 2:Open the matching .xml file of the class/trigger which we need to delete and change the status XML tag from "Active" to "Deleted".
Step 3:Save the file and then deploy the main class as well as associated .xml file to production.

Wednesday, February 3, 2016

How to change tab name( browser tab name) of Visualforce Page

Solution: Use document.title to give title.
Visualforce Page :
<apex:page>
<script type="text/javascript">
document.title = 'See Tab Name';
</script>

</apex:page>
Output :

Line Chart in Visualforce Page

Apex Class: 
public class LineChartController {
    // Return a list of data points for a chart
    public List<DataWrapper> getData() {
        return LineChartController.getChartData();
    }
    public static List<DataWrapper> getChartData() {
        List<DataWrapper> dataWrap= new List<DataWrapper>();
        dataWrap.add(new DataWrapper('JAN', 30));
        dataWrap.add(new DataWrapper('FEB', 44));
        dataWrap.add(new DataWrapper('MAR', 25));
        return dataWrap;
    }
   
    // Wrapper class
    public class DataWrapper {
        public String name { get; set; }
        public decimal data { get; set; }
        public dataWrapper(String name, integer value) {
            this.name = name;
            this.data = value;
        }
    }

}
Visualforce Page :
<apex:page controller="LineChartController">
    <apex:chart height="400" width="700" data="{!data}">
          <apex:axis type="Numeric" position="left" fields="data" 
            title="Opportunities Closed" grid="true"/>
          <apex:axis type="Category" position="bottom" fields="name" 
            title="Month of the Year">
        </apex:axis>
        <apex:lineSeries axis="left" fill="true" xField="name" yField="data"
          markerType="cross" markerSize="4" markerFill="#FF0000"/>
   </apex:chart>
</apex:page>
Output :