Multi picklist using visualforce and apex logic salesforce

VF :
-----
<apex:page controller="multiselect">
    <br/><br/><br/><br/>
    <center>
    <apex:form >
        <apex:panelGrid columns="3" id="abcd">
            <apex:selectList id="sel1" value="{!leftselected}" multiselect="true" style="width:100px" size="5">
                <apex:selectOptions value="{!unselectedvalues}" />
            </apex:selectList>
                <apex:panelGroup >
                    <br/>
                    <apex:image value="{!$Resource.multiselected}">
                        <apex:actionSupport event="onclick" action="{!selectclick}" reRender="abcd"/>
                    </apex:image>
                    <br/><br/>
                    <apex:image value="{!$Resource.multiunselected}">
                        <apex:actionSupport event="onclick" action="{!unselectclick}" reRender="abcd"/>
                    </apex:image>
                </apex:panelGroup>
            <apex:selectList id="sel2" value="{!rightselected}" multiselect="true" style="width:100px" size="5">
                <apex:selectOptions value="{!SelectedValues}" />
            </apex:selectList>
        </apex:panelGrid>
        <apex:commandButton value="Save" action="{!CmdSave}"/>
        {!s1}
    </apex:form>
    </center>
</apex:page>

Apex:
-------
public class multiselect {

    Set<String> originalvalues = new Set<String>{'Afghanistan ','Albania ','Algeria ','American Samoa ','Andorra ','Angola ','Anguilla ','Antigua & Barbuda ','Argentina ','Armenia ','Aruba ','Australia ','Austria ','Azerbaijan ','Bahamas, The ','Bahrain '};
    Public List<string> leftselected{get;set;}
    Public List<string> rightselected{get;set;}
    Set<string> leftvalues = new Set<string>();
    Set<string> rightvalues = new Set<string>();
   
    public multiselect(){
        leftselected = new List<String>();
        rightselected = new List<String>();
        leftvalues.addAll(originalValues);
    }
   
    public PageReference selectclick(){
        rightselected.clear();
        for(String s : leftselected){
            leftvalues.remove(s);
            rightvalues.add(s);
        }
        return null;
    }
   
    public PageReference unselectclick(){
        leftselected.clear();
        for(String s : rightselected){
            rightvalues.remove(s);
            leftvalues.add(s);
        }
        return null;
    }

    public List<SelectOption> getunSelectedValues(){
        List<SelectOption> options = new List<SelectOption>();
        List<string> tempList = new List<String>();
        tempList.addAll(leftvalues);
        tempList.sort();
        for(string s : tempList)
            options.add(new SelectOption(s,s));
        return options;
    }

    public List<SelectOption> getSelectedValues(){
        List<SelectOption> options1 = new List<SelectOption>();
        List<string> tempList = new List<String>();
        tempList.addAll(rightvalues);
        tempList.sort();
        for(String s : tempList)
            options1.add(new SelectOption(s,s));
        return options1;
    }
    public string s1 {get;set;}
    public void CmdSave(){
        s1 = '';
        for(string s : rightvalues ){
          s1 += s+';';
        }
    }
}

Screenshot :
--------------


Upload Contact Records Using Apex in bulk format

VF:
----
<apex:page controller="UploadRecords" sidebar="false" showHeader="true">
    <apex:form >
        <apex:pageBlock >        
        <apex:pageBlockSection columns="3">
        <marquee>Choose Upload File</marquee>
        <apex:inputFile value="{!contentFile}" fileName="{!nameFile}"></apex:inputFile>
        <apex:commandButton value="Upload" action="{!ReadFile}"/>
        </apex:pageBlockSection>
        </apex:pageBlock>
        <apex:pageBlock >
            <apex:pageBlockSection columns="1">
                 <apex:pageBlockTable value="{!conn}" var="c">
                     <apex:column value="{!c.lastname}"/>
                     <apex:column value="{!c.phone}"/>
                     <apex:column value="{!c.email}"/>
                 </apex:pageBlockTable>   
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Apex :
------
public class UploadRecords{
    public string nameFile{get;set;}
    public Blob contentFile{get;set;}
    String[] filelines = new String[]{};    
    List<Contact> accstoupload;    
    public Pagereference ReadFile(){
        nameFile=contentFile.toString();
        filelines = nameFile.split('\n');
        accstoupload = new List<Contact>();                
        for (Integer i=1;i<filelines.size();i++){
            String[] inputvalues = new String[]{};
            inputvalues = filelines[i].split(',');            
            Contact a = new Contact();
            a.lastName = inputvalues[0];
            a.phone=inputvalues[1];
            a.email=inputvalues[2];            
            accstoupload.add(a);
        }        
        insert accstoupload;        
        return null;
    }       
    Public List<Contact> getConn(){
        return accstoupload;
    }
}

Parent with child records in same page

VF:
-----
<apex:page controller="WrapperClassForAccountAndRelatedContacts" sidebar="false"  standardStylesheets="false">
     <apex:form >                   
            <apex:pageblock >             
             <apex:repeat value="{!AccountsCons}" var="EAcc">
                   <apex:pageBlockSection title="{!EAcc.wrapAcct.name}" collapsible="true">
                       <apex:pageBlockTable value="{!EAcc.wrapCon}" var="Econ">
                            <apex:column >                               
                              <apex:outputField value="{!Econ.Name}" />                   
                            </apex:Column>                            
                            <apex:column >
                                <apex:outputField value="{!Econ.Phone}" />
                            </apex:Column>  
                            <apex:column >
                                <apex:outputField value="{!Econ.Email}" />
                            </apex:Column>                                      
                        </apex:pageBlockTable>                       
                   </apex:pageBlockSection>
                </apex:repeat>              
            </apex:pageblock>
         </apex:form>       
</apex:page>

Class :
-------

public with sharing class WrapperClassForAccountAndRelatedContacts{     public list<Account> lstAcc{get;set;}     public List<Contact> conList{get;set;}     public List<AccountWrapper> acctCon{get;set;}     public WrapperClassForAccountAndRelatedContacts(){         lstAcc = new list<Account>();         lstAcc = [select id,name,(select id,lastname,phone,Name,firstname,email from Contacts),phone from Account];                       conList = new  List<Contact>();         for(Account acc : lstAcc){            conList = acc.contacts;         }     }          public List<AccountWrapper> getAccountsCons(){      acctCon = new List<AccountWrapper>();      for(Account acct : lstAcc){         acctCon.add(new AccountWrapper(acct,acct.Contacts));                 }          return acctCon;     }         public class AccountWrapper{             public Account wrapAcct {get;set;}         public List<Contact> wrapCon {get;set;}         public AccountWrapper(Account acct, List<Contact> con){             this.wrapAcct =acct;             this.wrapCon = con;             }     }     } Screenshot : ------------

Visualforce pages in stadard page layout salesforce

<apex:page standardController="SFDC_Employee__c">
    <style type="text/css">
        * {
          font-family: Roboto;
        }

        div.message {
          position: relative;
          padding: 1px;
          padding-left: 35px;
          margin: 20px 10px;
          box-shadow: 0 2px 5px rgba(0, 0, 0, .3);
          background: #BBB;
          color: #FFF;
        }

        div.message.lost {
            color: white;
            background: red;
        }
       
        div.message.won {
            color: white;
            background: green;
        }
    </style>

    <link href="//fonts.googleapis.com/css?family=Roboto:300italic,400italic,400,300,600,700" rel="stylesheet" type="text/css" />
    <link href="//maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css" rel="stylesheet" />

   <div class="won message" style="display: {!IF(SFDC_Employee__c.Employee_Type__c= 'Full Time', '', 'none')}" >
      <h2>Employee : This Employee is Full Time person</h2>
    </div>
   
    <div class="lost message" style="display: {!IF(SFDC_Employee__c.Employee_Type__c= 'Part Time', '', 'none')}" >
      <h2>Employee : This Employee is Part Time person</h2>
    </div>
</apex:page>



Action status with in command button salesforce

<apex:pageBlockSection id="Buttons" columns="1" collapsible="true">
                <apex:pageBlockSectionItem id="changePasswordButton">
                    <apex:outputLabel value="" styleClass="labelCol"/>
     <apex:actionStatus id="mySaveStatus1">     
     <apex:facet name="stop">                
     <apex:commandButton action="{!changePassword}" status="mySaveStatus1" value="Change Password" disabled="{!smsResponse.jobID=='0'}" rerender="ResultsSection, Buttons"/>          
     </apex:facet>          
     <apex:facet name="start">     
     <apex:commandButton action="{!changePassword}" status="mySaveStatus1" value="Processing..." disabled="true" />
     </apex:facet>
     </apex:actionStatus>
                </apex:pageBlockSectionItem>
            </apex:pageBlockSection>


dynamically Calling apex from java script custom button based on pick list value

Javascript :
-------------

{!REQUIRESCRIPT("/soap/ajax/30.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/24.0/apex.js")}
var ReferraAccepted = sforce.connection.query("SELECT id from {!Account.Routing_Rule__c} where AccountId ='{!Account.Id}'");
records = ReferraAccepted.getArray("records");
alert(records);
if (!records.length > 0) {
alert("There were no child records been assigned !!")
}
else {
window.open('/apex/RoutingRuleLogic?Id={!Account.Id}&objectName={!Account.Routing_Rule__c}', '_blank', 'height=600,width=600,resizable=yes,scrollbars=yes,toolbar=n‌​o,menubar=no');
}

Visualforce Page :
--------------------

<apex:page controller="RoutingRuleLogic_CLS" sidebar="false" showHeader="false">
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockTable value="{!objectDetails}" var="a">
                <apex:column value="{!a.id}"/>
                <apex:column headerValue="Name">
                <apex:outputText value="{!a['name']}"/>
                </apex:column>
                <apex:column headerValue="Email">
                <apex:outputText value="{!a['email']}"/>
                </apex:column>
                <apex:column headerValue="Phone">
                <apex:outputText value="{!a['phone']}"/>
                </apex:column>
                <apex:column headerValue="Account Id">
                <apex:outputText value="{!a['Accountid']}"/>
                </apex:column>
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Apex Logic :
---------------
public with sharing class RoutingRuleLogic_CLS {
    public string objectName {get;set;}
    public String query {get;set;}  
    public RoutingRuleLogic_CLS(){
        objectName = apexpages.currentpage().getparameters().get('objectName');
        if(objectName != '' && objectName != NULL){
            getRecordsBasedOnObjectName(objectName);
        }              
    }
    public list<sObject> objectDetails {get;set;}
    public Map<String,Schema.SObjectType> schemaGlobalDescription ;
    public Schema.sObjectType objType ;
    public Map<String,Schema.SObjectField> mapFieldList;
    public void getRecordsBasedOnObjectName(string objectName){
        query = 'Select ';
        schemaGlobalDescription  = Schema.getGlobalDescribe();
        objType = schemaGlobalDescription.get(objectName);
        Schema.DescribeSObjectResult objDescribeSObjectResult = objType.getDescribe();
        mapFieldList = objDescribeSObjectResult.fields.getMap();      
        for(Schema.SObjectField field : mapFieldList.values()){
            Schema.DescribeFieldResult fieldResult = field.getDescribe();
            if(fieldResult.getName() == 'Id'){          
            }else{
                query += fieldResult.getName()+ ',';
            }
        }
        query += ' Id from '+objectName+' limit 100';      
        objectDetails = new list<sObject>();
        if(String.isNotBlank(query)){
            objectDetails = database.query(query);
        }            
    }
}

Get all the fields of sObject dynamically salesforce?

String qid = 'a0A2800000HVQSc';
String objectName = 'Employees__c';
List<String> objFields =  new List<String>();
Map<String,Schema.SObjectType> schemaGlobalDescription = Schema.getGlobalDescribe();
Schema.sObjectType objType = schemaGlobalDescription.get(objectName);
Schema.DescribeSObjectResult objDescribeSObjectResult = objType.getDescribe();
Map<String,Schema.SObjectField> mapFieldList = objDescribeSObjectResult.fields.getMap();
String commaSepratedFields ='';
for(Schema.SObjectField field : mapFieldList.values()){
    Schema.DescribeFieldResult fieldResult = field.getDescribe();
        commaSepratedFields += fieldResult.getName()+',';
}
commaSepratedFields = commaSepratedFields.substring(0,commaSepratedFields.length()-1);
String query = 'select ' + commaSepratedFields + ' from Employees__c Limit 1';
system.debug(query);
list<Employees__c> listEMP = database.query(query);
system.debug(listEMP);

Featured

What is Cryptography in salesforce and what are all the algorithms provided by them ?

A). It is a security protocal between two systems. Lets say we are integration two systems without any encrytion mechanism then hackers wil...

Popular