Wednesday, January 21, 2015

Salesforce - Using Jquery DataTable for pagination and sorting in visualforce page

<apex:page showHeader="false" sidebar="false" controller="ControllerName"  standardStylesheets="false">
    
    <link rel="stylesheet" type="text/css" href="//cdn.datatables.net/1.10.4/css/jquery.dataTables.css"></link>    
    <apex:includeScript value="https://code.jquery.com/jquery-1.11.1.min.js"/>
    <apex:includeScript value="https://cdn.datatables.net/1.10.4/js/jquery.dataTables.min.js"/>    
    <apex:includeScript value="https://code.jquery.com/jquery-1.10.2.min.js"/>
    <apex:includeScript value="https://cdn.datatables.net/1.10.4/js/jquery.dataTables.js"/> 
      
    <apex:form >       
        <table id="projectTable" class="table-project" >
            <thead>
            <tr>                     
                <th> Project Name </th>                        
            </tr>
            </thead>
            <tbody>
// projectList - is controller List
            <apex:repeat value="{!projectList}" var="pro">
                <tr>                    
                    <td>
                            {!pro.Name}                       
                    </td>
                   
                </tr>
            </apex:repeat>
            </tbody>
        </table>
    </apex:form>    
    <script>
        var j$ = jQuery.noConflict();
        j$(document).ready(function() {
            $('#projectTable').DataTable(    
                {                    
                    "searching": false,
                    "lengthChange": false,
                    "pageLength": 25,
                    "info": false                  
                }         
            );
        } );
    </script>
    <!--
       // To sort the date column
       // [5] - is 5th column from 0 
                    "aoColumnDefs": [
                        { "sType": "date", "aTargets": [ 5 ] }
                     ]           
        //To seeting the width
        { "sWidth": "100px", "aTargets": [ 5 ] },
        { "sWidth": "100px", "aTargets": [ 4 ] },
        { "sWidth": "100px", "aTargets": [ 3 ] }
    -->
</apex:page>

Monday, January 5, 2015

Salesforce code for Mass Update from List View

 Sample code for Opportunity

List view  Button Code

{!REQUIRESCRIPT("/soap/ajax/9.0/connection.js")}

var records = {!GETRECORDIDS( $ObjectType.Opportunity)};

if (records[0] == null ) {
    alert("Please select at least one record.")
} else {
    window.location = '/apex/OpportunityChangeStatus?Id=' + records;
}

Page

<apex:page standardController="Opportunity" extensions="OpportunityChangeStatus" recordSetVar="opp">
    <apex:form >
    <apex:pageBlock >
        <apex:pageBlockButtons >
            <apex:commandButton value="Save" action="{!save}"/>
            <apex:commandButton value="cancel" action="{!cancel}"/>
        </apex:pageBlockButtons>
        <apex:pageBlockSection >
            <apex:pageBlockSectionItem >
                <apex:outputLabel > Select a stage:</apex:outputLabel>
                <apex:inputField value="{!oppRec.StageName}"/>
            </apex:pageBlockSectionItem>    
        </apex:pageBlockSection>
    </apex:pageBlock>
    </apex:form>
</apex:page>

Controller

public class OpportunityChangeStatus {
    
    public Opportunity oppRec{get;set;}
    List<Opportunity> oppList = new List<Opportunity>();
    List<String> oppIdList = new List<String>();
    List<Opportunity> updatedOppList = new List<Opportunity>();
    
    public OpportunityChangeStatus(ApexPages.StandardController controller) {
        
    }
    
    private ApexPages.StandardSetController standardController;
    public OpportunityChangeStatus(ApexPages.StandardSetController standardController){
        oppRec = new Opportunity();        
        String oppId = ApexPages.currentPage().getParameters().get('id');
        oppIdList = oppId.split(',');       
    }
    public Pagereference save(){    
        
        for(String oppId : oppIdList){
            Opportunity opp = new Opportunity();
            opp.Id = oppId;
            opp.StageName = oppRec.StageName;
            updatedOppList.add(opp);
        }        
        if(updatedOppList.size() > 0){
            update updatedOppList;
        }        
        return new PageReference('/006');
    }
}

Salesforce Useful URL's - Part II


How to Customize the Lead Conversion Process in Salesforce.com

http://bulkified.com/How+to+Customize+the+Lead+Conversion+Process+in+Salesforce.com

Bulk attachment, content and document migration using Apex Dataloader

http://bulkified.com/Bulk+attachment%2c+content+and+document+migration+using+Apex+Dataloader

Preventing focus of first input field and Calendar widget on page load in Salesforce

http://bulkified.com/Preventing+focus+of+first+input+field+and+Calendar+widget+on+page+load+in+Salesforce

Salesforce How to Debug / Troubleshoot using the Salesforce Debug Logs

http://nickforce.blogspot.in/2011/11/salesforce-how-to-debug-troubleshoot.html#more

Visualforce component basic examples 

http://nickforce.blogspot.in/2011/04/visualforce-component-basic-examples.html#more

Salesforce - Generate dynamic inner query to fetch parent and related child records

Use Case: In many scenarios, we need to clone the records with related child records. Issue / Limitation: We may simply use the "cl...