+ Start a Discussion
Koustubh KulkarniKoustubh Kulkarni 

Bulk update record from VF page?

Hi I am new to salesforce.I have one inline VF page on contacts layout. I have written following code to bulk update various records on a custom object, but it is not working properly.
VF page-
<apex:page standardController="contact"  extensions="cntrl_bulk_test"> <!-- controller="cntrl_bulk_test" -->
    <apex:form >
        <apex:pageBlock id="pgBlkSkilllevel">
            <apex:pageBlockTable value="{!lsttopiclevel}" var="a">
                
                <apex:column headerValue="Skill Group">
                    <apex:outputField value="{!a.Skill_Group__c}"/>
                  <!--  <apex:inputfield value="{!a.Skill_Group__c}"/> -->
                </apex:column>
                  
                <apex:column headerValue="Topic Name">
                    <apex:outputField value="{!a.Topic__r.Name}"/>
                </apex:column>
                  
                <apex:column headerValue="Skill Target">
                    <apex:outputField value="{!a.skill_level_expected__c}"/>
                </apex:column>
                  
                <apex:column headerValue="Skill Level">
                    <apex:inputfield value="{!a.Skill_Level__c}"/>
                </apex:column>
                  
                <apex:column headerValue="Year">
                    <apex:inputfield value="{!a.Year__c}"/>
                </apex:column>  
                
                <apex:column headerValue="Quarter">
                    <apex:inputfield value="{!a.Quarter__c}"/>
                </apex:column>    
                
            </apex:pageBlockTable>
        <br/>
       
        <apex:commandButton value="Save" action="{!saveSkillLevelRating}"  reRender="pgBlkSkilllevel"/>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Controller-
public with sharing class cntrl_bulk_test
{
    Public static Id EmployeeId {get;set;}
    Public static List<Contact_Topic_Scale__c> lsttopiclevel{get;set;}
    
    public cntrl_bulk_test(ApexPages.StandardController controller)
    {
         EmployeeId =system.currentpagereference().getparameters().get('id');
         Contact coninfo = [select name from contact where id =: EmployeeId];
         lsttopiclevel = new List<Contact_Topic_Scale__c>([SELECT Id, Core_Skill_Set__c,Contact_Skill_Set__c,Delta_Actual_vs_Expected__c,Employee__c,Quarter__c,Skill_Group__c,Skill_Level__c,skill_level_expected__c,Year__c,Topic__r.Name FROM Contact_Topic_Scale__c where Employee__c =: coninfo.name ORDER BY Skill_Group__c ASC ]);
    }
 
    Public PageReference saveSkillLevelRating()
    {
           System.debug('*******saveSkillLevelRating0*******');
         
           PageReference pageRef = ApexPages.currentPage();
           update lsttopiclevel;
           return pageRef ;
    }   
}

Can anyone help me with this issue?
 
Alexander TsitsuraAlexander Tsitsura
Hi Koustubh,

You need call save method or use dml for save changes. Try my code below
 
public with sharing class cntrl_bulk_test
{
    Public static Id EmployeeId {get;set;}
    Public static List<Contact_Topic_Scale__c> lsttopiclevel{get;set;}
   public ApexPages.StandardController controller {get; set;}    

    public cntrl_bulk_test(ApexPages.StandardController controller)
    {
         this.controller = controller;
         EmployeeId =system.currentpagereference().getparameters().get('id');
         Contact coninfo = [select name from contact where id =: EmployeeId];
         lsttopiclevel = new List<Contact_Topic_Scale__c>([SELECT Id, Core_Skill_Set__c,Contact_Skill_Set__c,Delta_Actual_vs_Expected__c,Employee__c,Quarter__c,Skill_Group__c,Skill_Level__c,skill_level_expected__c,Year__c,Topic__r.Name FROM Contact_Topic_Scale__c where Employee__c =: coninfo.name ORDER BY Skill_Group__c ASC ]);
    }
 
    Public PageReference saveSkillLevelRating()
    {
           controller.save(); // call save method from standart controller
           System.debug('*******saveSkillLevelRating0*******');
         
           PageReference pageRef = ApexPages.currentPage();
           update lsttopiclevel;
           return pageRef ;
    }   
}


As a common practice, if your question is answered, please choose 1 best answer. 
But you can give every answer a thumb up if that answer is helpful to you.

Thanks,
Alex
Koustubh KulkarniKoustubh Kulkarni
Thank you Alex for your help.But the code you provided is not  updating records.

Thanks,
Koustubh