0

Hi I am new to salesforce.I have one inline VF page on contacts layout. I have written following code to show existing records of that contact and bulk update various records of a custom object, but it is not updating properly. VF page-

<apex:page standardController="contact"  extensions="cntrl_bulk_test"> <!-- controller="cntrl_bulk_test" -->
    <apex:form id="frm">
        <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}" onclick="window.top.location='/{!Contact.id}'; return false"/>
        </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;}
    list<Contact_Topic_Scale__c> LstSkilllevels = new list<Contact_Topic_Scale__c>();
   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 = system.currentpagereference();
           PageReference pageRef = ApexPages.currentPage();
           LstSkilllevels=lsttopiclevel;
           update LstSkilllevels;
           return null;
           //return pageRef ;

    }   
}

Can anyone help me with this issue?Any kind of help will be appreciated. Thanks.

1 Answer 1

0

For data to be properly passed to and from the browser the data field must not be static. So your controller should look something like this:

public with sharing class cntrl_bulk_test {

    private ApexPages.StandardController sc;
    public List<Contact_Topic_Scale__c> lsttopiclevel {get;set;}

    public cntrl_bulk_test(ApexPages.StandardController sc) {
        this.sc = sc;
        Contact coninfo = [select name from contact where id =:sc.getId()];
        lsttopiclevel = [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() {
        update lsttopiclevel;
        return sc.view();
    }   
}

You do not need the onclick on the apex:commandButton - the value returned by the saveSkillLevelRating method determines the next page.

7
  • Thanks keith but Its still not updating anything the records.
    – koustubh
    Oct 14, 2015 at 8:53
  • @koustubh Weird. You have removed the onclick? And if you add System.debug('lsttopiclevel=' + lsttopiclevel); to the saveSkillLevelRating do you see the edited values?
    – Keith C
    Oct 14, 2015 at 9:05
  • @keith-yes i removed onclick and after adding System.debug('lsttopiclevel=' + lsttopiclevel); to the saveSkillLevelRating i got lsttopiclevel=null. I am not getting what i have done wrong.and also in saveSkillLevelRating log im getting this error-FATAL_ERROR System.NullPointerException: Attempt to de-reference a null object
    – koustubh
    Oct 14, 2015 at 9:27
  • @koustubh Are you using exactly the code in my answer e.g. did you cut and paste it?
    – Keith C
    Oct 14, 2015 at 9:33
  • not cut paste, i made the appropriate changes
    – koustubh
    Oct 14, 2015 at 9:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .