0

I've a problem and can't get solution. I'd like to make some operations on some fields of selected records in a visualforce datatable, but it doesn't work.

Controller:

public class AccountToMove{   
    public Campaign campaigndetail{ get; set; }
    public String teleagentchoosed{ get; set; }      
    public List<SelectOption> teleagentOptions=new List<SelectOption>();     
    public List<cAccount> accList {get; set;}
    public List<Account_Campaign__c> selectedAccounts{get; set;}

    //Adding the Records to inner class and to get the values for page block table.
    public List<cAccount> getAccounts(){
        if(accList == null){
            accList = new List<cAccount>();
            for(Account_Campaign__c acc : [select Number_of_employees__c,Annual_revenue__c,End_User_Name__c,
                                           Profiled_by__c,ID,Name,Teleagent__c,Status__c,Total_number_of_call__c,Recall_date__c,
                                           last_call__c,Priority__c,Account_Campaign__c,Group_ID__c,Call_Meeting_date_result__c
                                           FROM Account_Campaign__c WHERE Account_Campaign__c=:this.campaigndetail.id ]){
                accList.add(new cAccount(acc));
            }
        }
        return accList;
    }  

    public PageReference changeAgent(){     
        selectedAccounts= new List<Account_Campaign__c>();
        for(cAccount cCon : getAccounts()){
            if(cCon.selected == true){
                selectedAccounts.add(cCon.con);
            }
        }     
        for(Account_Campaign__c ok : selectedAccounts){            
            ok.Teleagent__c=teleagentchoosed;            
        }            
        update selectedAccounts; 
        return null;
    }

    //  Inner class for capture the records
    public class cAccount{
        public Account_Campaign__c con {get; set;}
        public Boolean selected {get; set;}
        public cAccount(Account_Campaign__c c){
            con = c;
            selected = false;
        }
    }

    public map<String,Schema.SObjectType> sobjectMap = Schema.getGlobalDescribe();
    public List<SelectOption> getPickListOptions(String objectName, String fieldName){
        List<SelectOption> picklistOptions = new list<SelectOption>();
        Schema.Sobjecttype sobjectResult = sobjectMap.get(objectName);

        map<String, Schema.SObjectField> field_map = sobjectResult.getDescribe().fields.getMap();

        List<Schema.Picklistentry> picklistValuesList = field_map.get(fieldName).getdescribe().getPickListValues();
        for(Schema.Picklistentry picklistValues : picklistValuesList){
            picklistOptions.add(new Selectoption(picklistValues.getLabel(), picklistValues.getValue()));
        }        
        return picklistOptions;
    }

    public List<SelectOption> getteleagentOptions(){        
        teleagentOptions=getPickListOptions('Account_Campaign__c', 'Teleagent__c');

        return teleagentOptions;
    }    
}

VF Page:

<apex:page standardController="Campaign" showHeader="false" sidebar="false"
           tabStyle="Campaign" extensions="AccountToMove" >
    <apex:pageBlock>
        <apex:form>
            <apex:commandButton value="Change selected to teleagent " action="{!changeAgent}"  rerender="all" />
            <apex:selectList size="1" value="{!teleagentchoosed}">
                <apex:selectOptions value="{!teleagentOptions}"/> 
            </apex:selectList>

            <hr/>

            <apex:pageBlockTable value="{!AllAccount}" var="camp1" id="all">                
                <apex:column headerValue="Select" >
                    <apex:inputCheckbox value="{!camp1.selected}"/>
                </apex:column>

                <apex:column headerValue="Account Name" > 
                    <apex:outputLink value="/{!camp1.am.id}">{!camp1.am.End_User_Name__c} </apex:outputLink>    
                </apex:column> 

                <apex:column headerValue="Employees" value="{!camp1.am.Number_of_employees__c}"/>  

                <apex:column headerValue="Revenue"  value="{!camp1.am.Annual_revenue__c}"/> 

                <apex:column headerValue="Group" value="{!camp1.am.Group_ID__c}"/> 

                <apex:column headerValue="Priority" value="{!camp1.am.Priority__c}"/> 

                <apex:column headerValue="Status" value="{!camp1.am.Status__c}"/> 

                <apex:column headerValue="Total number of call" value="{!camp1.am.Total_number_of_call__c}"/> 

                <apex:column headerValue="Teleagent" value="{!camp1.am.Teleagent__c}"/> 

                <apex:column headerValue="Profiled by" value="{!camp1.am.Profiled_by__c}"/> 

                <apex:column headerValue="Recall date" > 
                    <apex:outputField value="{!camp1.am.Recall_date__c}" />
                </apex:column> 

                <apex:column headerValue="Last call" > 
                    <apex:outputField value=" {!camp1.am.Last_call__c}" />
                </apex:column> 

                <apex:column headerValue="Meeting/call date" > 
                    <apex:outputField value="{!camp1.am.Call_Meeting_date_result__c}" />   
                </apex:column>                 
            </apex:pageBlockTable>
        </apex:form>
    </apex:pageBlock>
</apex:page>
  • maybe you can add some information on what doesn't work. Do you get anything on the screen? – Guy Clairbois Jul 4 '14 at 15:04
  • The problem is that when I press the Change selected to teleagent button, I expect that the selected record have an assigned teleagent, but they don't. The table does not refresh (it should , because of rerender ="all", and nothing happens – user9959 Jul 4 '14 at 15:25
  • is the problem with only the table not getting refreshed? Are the accounts been updated with the assigned teleagent? – Prady Jul 4 '14 at 16:10
  • the pageBlocktable refers to controller variable allAccount but that variable is not shown in your post. Is it being refreshed with the latest data after the action is executed? – cropredy Jul 4 '14 at 16:16
  • try changing for(cAccount cCon : getAccounts()) { with for(cAccount cCon : allAccount) { – Prady Jul 4 '14 at 16:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy