Show or Hide fields in visualforce page using action function

VF:
----
<apex:page controller="actionFunctionController" tabStyle="Account">
    <apex:form >
        <apex:actionFunction name="priorityChangedJavaScript" action="{!priorityChanged}" rerender="out"/>
        <apex:pageBlock >
            <apex:pageBlockSection title="If you will select High Customer Priority then phone textbox will be shown" columns="1" id="out" collapsible="false">
                <apex:inputField value="{!acc.CustomerPriority__c}" onchange="priorityChangedJavaScript()"/>
                <apex:inputField value="{!acc.Phone}" rendered="{!showPhone}"/>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Apex:
-----
public class actionFunctionController {
    public Account acc{get;set;}
    public Boolean showPhone{get;set;}
 
    public actionFunctionController(){
        acc = new Account();
        showPhone = false;
    }
 
    public PageReference priorityChanged(){
        if(acc.CustomerPriority__c == 'High'){
            showPhone = true;
        }
        else{
            showPhone = false;
        }
        return null;
    }
}

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

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 : ------------

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