Ads

Showing posts with label Apex. Show all posts
Showing posts with label Apex. Show all posts

Sunday 26 May 2013

We have three country buttons, if we click any button that country information should only display?

Apex:
public class coun {

    public Boolean hide = false;
    public Boolean hide1 = false;
    public Boolean hide2 = false;
    
    public void setMhide(Boolean b) {
    this.hide = b;
    }
    
    public Boolean getMhide() {
    return this.hide;
    }//Passing input dynamically through another method
    
    
    public Boolean getM1hide() {
        return this.hide2;
    }
    
    public void setM1hide(Boolean b) {
      this.hide2 = b;  
    }
    
    
    public Boolean getM2hide() {
        return this.hide1;
    }
    
    public void setM2hide(Boolean b) {
        this.hide1 = b;
    }
    
    
    public PageReference india() {
        setMhide(true);
        setM2hide(false);
        setM1hide(false);     
        return null;
    }//displaying only india information and hiding other information
    
     public PageReference us() {
        setM1hide(true);
        setM2hide(false);
        setMhide(false);
        return null;
    }
    
    public PageReference uk() {
        setM2hide(true);
        setM1hide(false);
        setMhide(false);
        return null;
    }   
    
}
Vf Page:
<apex:page controller="coun">
<apex:form >

<apex:commandButton value="India" action="{!india}" reRender="India,Us,Uk"/>
<apex:commandButton value="Us" action="{!us}" reRender="India,Us,Uk"/>
<apex:commandButton value="Uk" action="{!uk}" reRender="India,Us,Uk"/>

<apex:pageBlock >

<apex:outputPanel id="India">
<apex:pageBlockSection title="India" rendered="{!mhide}">
</apex:pageBlockSection>
</apex:outputPanel>
<apex:outputpanel id="Us">
<apex:pageBlockSection title="US" rendered="{!m1hide}">
</apex:pageBlockSection>
</apex:outputpanel>

<apex:outputpanel id="Uk">
<apex:pageBlockSection title="UK" rendered="{!m2hide}">
</apex:pageBlockSection>
</apex:outputpanel>

</apex:pageBlock>

</apex:form>
</apex:page>



How To retrieve the records of the custom/standard object of the current user?

Solution:

Id aid = Userinfo.getUserId();
account ac = [Select Id, Name from Account Where CreatedById = : aid limit 1];
System.debug(' ---- ' + ac );

or

Id aid = Userinfo.getUserId();
List<Account> ac = [Select Id, Name From Account Where CreatedById = : aid Limit 10000];  


Thursday 16 May 2013

Custom Multi-Select picklist field in Visualforce?


There are several scenarios, where in we might have used input field for getting multi-select picklist field. What if you can’t really use an input field, here is the example code which will solve these type of problems.
Mutli-Select
VFPage Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<apex:page controller="multiselect">
    <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:form>
</apex:page>
Controller Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
public class multiselect {
    Set<String> originalvalues = new Set<String>{'A','B','C','D','E','F','G'};
    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;
    }
}