4

I have a VF page which I am accessing using - test.salesforce.com/apex/VFpage?id=xxx. I have a save and edit button on VF page which I have defined in my extension class.

VF Page(part in scope of this question):

     <apex:pageBlock >
                <apex:pageBlockButtons >
                    <apex:commandButton value="Save" action="{!saveIF}" />
                    <apex:commandButton value="Edit" action="{!edit}" /> 
                </apex:pageBlockButtons>

    <apex:pageBlockSection title="A Pageblocksection" columns="1" >
     <apex:outputfield value="{!object.game}"  rendered="{!NOT(Mode)}"/>
     <apex:inputfield value="{!object__c.game}"  rendered="{!Mode}"/>
    </apex:pageBlockSection>


    <apex:pageBlockSection title="A Pageblocksection" columns="1" >
<apex:pageblocktable value="{!variable}" var="aVar">

    .... Some fields are displayed from aVar , like aVar.field1__c,aVar.field2__c
    and there is some input I get from user and update the field1 and field2.

</apex:pageblocktable>
    </apex:pageBlockSection>

In my controller , I am setting the Mode value as true or false depending on edit

    class extension{

    pagereference saveIF(){

... do some logic and update the record.
Mode=false; // user can see fields with rendered="{!Mode}" 

    }

    pagereference edit(){
    Mode = true; // user can see fields with rendered="{!NOT(Mode)}"

    }


    }

My Problem here: When I click edit and save the record the fields are not getting updated. But when I refresh the page the fields are getting the updated values. How can I refresh the page when user hits save button?

What I tried - I tried rerendered in save button button the pageblock table section does not get updated with the values after user clicks save. It shows only the previous values.

Actual VF Page:

<apex:page standardController="Interview__c" extensions="InterviewattachmentPDFExtension" docType="html-5.0" >
<style>
  .cke_contents {
    height: 100px !important;
  }
</style>

    <apex:form >

        <apex:pageBlock id="techid">
            <apex:pageBlockButtons >
                <apex:commandButton value="Save" action="{!saveInterviewerFeedback}" />
                <apex:commandButton value="Edit" action="{!edit}" reRender="techid"/> 
                <apex:commandButton action="{!sendEmail}" value="Send an email"/>
            </apex:pageBlockButtons>
            <apex:pageBlockSection title="INTERVIEW EVALUATION SHEET" columns="1">               
                <table border="0" cellpadding="1" style="width:100%">
                    <apex:outputField value="{!interview.Name__c}"/>

                    <apex:outputField value="{!interview.Job_Application__c}"/>
                    <apex:outputField value="{!interview.Interviewer_Feedback__c}" rendered="{!NOT(interviewerMode)}"/>
                    <apex:inputField value="{!Interview__c.Interviewer_Feedback__c}" rendered="{!interviewerMode}" style="width:100%"/>                    
                    <apex:outputField value="{!interview.Interviewed_Date__c}" rendered="{!NOT(interviewerMode)}"/>
                    <apex:inputField value="{!Interview__c.Interviewed_Date__c}" rendered="{!interviewerMode}" />
                    <apex:outputField value="{!interview.Interview_Mode__c}" rendered="{!NOT(interviewerMode)}"/>
                    <apex:inputField value="{!Interview__c.Interview_Mode__c}" rendered="{!interviewerMode}"/> 
                    <apex:outputField value="{!interview.Interviewer_Emp_ID__c}"/>
                    <apex:outputField value="{!interview.Interviewer_Name__c}"/>
                    <apex:outputField value="{!interview.Additional_Interviewer__c}" rendered="{!NOT(interviewerMode)}"/>
                    <apex:inputField value="{!Interview__c.Additional_Interviewer__c}" rendered="{!interviewerMode}"/>  
                    <apex:outputField value="{!interview.Hiring_Manager_Copy__c}"/>
                    <apex:outputField value="{!interview.Years_Of_Experience__c}"/> 
                    <apex:outputField value="{!interview.Client_Name__c}"/> 
                    <apex:outputField value="{!interview.Business_Unit__c}"/>
                    <apex:outputField value="{!interview.Recommendations__c}" rendered="{!NOT(interviewerMode)}"/>
                    <apex:inputField value="{!Interview__c.Recommendations__c}" rendered="{!interviewerMode}" /> 
                    <apex:outputField value="{!interview.Fitment_Level__c}" rendered="{!NOT(interviewerMode)}"/>
                    <apex:inputField value="{!Interview__c.Fitment_Level__c}" rendered="{!interviewerMode}" />
                </table> 
            </apex:pageBlockSection>
            <!-- 
            <apex:pageBlockSection title="EVALUATION" columns="1">

    <apex:pageblockTable value="{!evaluationList}" var="evel">
        <apex:column headerValue="Parameters">  
            <apex:outputLabel value="{!evel.review}" />   
        </apex:column>

           <apex:column headerValue="Rating">                        
                <apex:selectList value="{!rating}" multiselect="false" size="1" rendered="{!interviewerMode}" >
                                <apex:selectOption itemValue="1" itemLabel="1"/>
                                <apex:selectOption itemValue="2" itemLabel="2"/>
                                <apex:selectOption itemValue="3" itemLabel="3"/>
                                <apex:selectOption itemValue="4" itemLabel="4"/>
                                <apex:selectOption itemValue="5" itemLabel="5"/>
                 </apex:selectList>     
           </apex:column>

            </apex:pageblockTable>

            </apex:pageBlockSection>
-->


            <apex:pageBlockSection columns="1" title="TECHNICAL ASSESSMENT">

                <apex:repeat value="{!interviewSkillReviews}" var="interview">


                        <apex:pageblockTable value="{!interview.Skill_review__r}" var="skillreview">
                        <table border="1px">
                        <apex:outputText value="{!skillreview.Skill__r.Name}"></apex:outputText>

                            <apex:column headerValue="Skill Name">                                
                                <apex:outputText value="{!skillreview.Skill__r.Name}"/>
                            </apex:column>
                        <apex:column headerValue="Recommended Level">
                            <apex:outputText value="{!skillreview.Level__r.Name}"/>
                        </apex:column>

                        <apex:column headerValue="Rating">
                            <apex:outputField value="{!skillreview.RatingCopy__c}" rendered="{!NOT(interviewerMode)}"/>
                            <apex:selectList value="{!rating}" multiselect="false" size="1" rendered="{!interviewerMode}" >
                                <apex:selectOption itemValue="1" itemLabel="1"/>
                                <apex:selectOption itemValue="2" itemLabel="2"/>
                                <apex:selectOption itemValue="3" itemLabel="3"/>
                                <apex:selectOption itemValue="4" itemLabel="4"/>
                                <apex:selectOption itemValue="5" itemLabel="5"/>
                            </apex:selectList>
                        </apex:column>

                        <apex:column headerValue="Rating Level Description">
                            <apex:outputText value="{!skillreview.Skill_Level_Description__c}"/>
                        </apex:column>
                         </table>

                    </apex:pageblockTable>

            </apex:repeat>
        </apex:pageBlockSection>




    </apex:pageBlock>    




</apex:form>

</apex:page>

Actual Extension:

public class InterviewattachmentPDFExtension{

    public Interview__c interview{get;set;}
    public boolean interviewerMode {get;private set;} // make it global, set to true when sending pdf
    public Interview__c interviewSkillReviews {get;set;} // child relationship
    public String rating{get;set;}
    public List<SkillReviewWrapper> SkillReviewList{get;set;}
    public List<skillHelper> evaluationList{get;set;}
    public ApexPages.StandardController standrdController;

    public InterviewattachmentPDFExtension(ApexPages.StandardController controller) {

        interview=(Interview__c)controller.getRecord();
        standrdController = new ApexPages.StandardController(interview);
        standrdController=controller;
        interview=[select Job_Application__c,Image__c,Name__c,Interviewer_Feedback__c,Interviewed_Date__c,Interview_Mode__c,Interviewer_Name__c,Hiring_Manager__c, 
                        Years_Of_Experience__c,Client_Name__c,Business_Unit__c,Recommendations__c,Interviewer_Emp_ID__c,Hiring_Manager_Copy__c,Additional_Interviewer__c,Fitment_Level__c from Interview__c where id=:interview.id];
        system.debug('Interview fields *************************************************' + this.interview.Job_Application__c);
        interviewSkillReviews = [select id,name, (select Name,Skill__r.Name,Level__r.Name,Skill_Level_Description__c,RatingCopy__c from Skill_review__r) from Interview__C where id=:interview.id];
        if(ApexPages.currentPage().getParameters().get('interviewerMode') == NULL){
            interviewerMode= true;
        }else{
            //interviewerMode = Boolean.valueOf(ApexPages.currentPage().getParameters().get('interviewerMode'));
            interviewerMode = false;
        }
        initSkillReviews(); 

    }

    private void initSkillReviews() {
        skillReviewList=new List<SkillReviewWrapper>();        
        for(Skill_Review__c sr: [SELECT Id,Name,Skill__c,Level__c,Skill_Level_Description__c,Rating__c,Level_of_Skill__c FROM Skill_Review__c where Interview__c =:interview.id ]){              
            skillReviewList.add(new SkillReviewWrapper(sr));
        }

        evaluationList = new List<skillHelper>();
        evaluationList.add(new skillHelper('Communication: Presentation of ideas, clarity of thought and expression'));
        evaluationList.add(new skillHelper('Attitude: Self-drive, flexibility and ownership towards the goal'));
        evaluationList.add(new skillHelper('Analytical Skills: Logic in presenting opinions & Views and Interpretation of Information'));
        evaluationList.add(new skillHelper('Job Knowledge & Skills:  Knowledge of concepts, Quality of experience in relevant areas'));
        evaluationList.add(new skillHelper('Leadership: Portrays the qualities and skills of a leader for the level of hiring'));
        evaluationList.add(new skillHelper('Overall rating: Not an average of the above ratings. Whether the above applicant matches the requirements for the position.'));
    }


    public pagereference saveInterviewerFeedback(){
        //IsEditMode = true;

        Set<String> setLevels = new Set<String>();
        for(SkillReviewWrapper obj: skillReviewList)
        {
            obj.rating=rating;
            setLevels.add(obj.rating);
        }

        map<String, Id> mapLevelName = new map<String, Id>();
        for(Level__c ratingObj:[SELECT Skill_of_Level__c,Id, Name FROM Level__c WHERE Name IN: setLevels ])
        {
            // store the id, name in a Map to be used later
            mapLevelName.put(ratingObj.Skill_of_Level__c, ratingObj.Id);
        }

        List<Skill_Review__c > updateLevelInSkillReview= new List<Skill_Review__c>();    
        for(SkillReviewWrapper obj: skillReviewList)
        {
            // put the level id in SkillreviewList's Level__c, to be updated in database
            // get the level id using the level name selected by user in picklist stored in SkillReviewList
            obj.skillReview.rating__c = mapLevelName.get(obj.skillReview.Level_of_Skill__c); 
            updateLevelInSkillReview.add(obj.skillReview);
        }    

       // Pagereference pgref= new Pagereference('/apex/InterviewattachmentPDF?id=' + interview.id + '&interviewerMode=false');
         interviewerMode = false;
        update updateLevelInSkillReview;
        //ApexPages.currentPage().getParameters().put('interviewerMode','false');
        standrdController.save();
        PageReference pageRef = new PageReference(ApexPages.currentPage().getUrl());
        //pageRef.setRedirect(true);
        return pageRef; 
        //return null;
    }


    public void sendEmail () { 
    OutboundEmails.SendEmailNotification(interview.id);
    }

    public pagereference edit(){
    interviewerMode = true;
    return null;
    }


}
5
  • Can you re-try setting 'reRender' on save button and update your code with the new changes and result? I believe reRender should work for you. Commented Jun 3, 2016 at 5:18
  • I have two pageblock section to rerender, How can I pass two ids to rerender in my save button? Thanks
    – SfdcBat
    Commented Jun 3, 2016 at 5:19
  • Is it a problem if you reRender the pageblock itself? Commented Jun 3, 2016 at 5:22
  • Yea, the other page block section could not be rerendered.
    – SfdcBat
    Commented Jun 3, 2016 at 5:25
  • I have copied full code of my VF and extension.
    – SfdcBat
    Commented Jun 3, 2016 at 5:28

2 Answers 2

4

try to rerender complete page or use pagereference to reload. Something like

return new pagereference('/'+recId);

This will solve the problem

or can do this

PageReference pageRef = new PageReference(ApexPages.currentPage().getUrl());
        pageRef.setRedirect(false);
        return pageRef;

or add a parameter something like

return new pagereference('/'+recId+'?interviewerMode=view');

and in the constructor

 public InterviewattachmentPDFExtension(ApexPages.StandardController controller) {
 // other code
if(ApexPages.currentPage().getParameters().get('interviewerMode') == 'view){
            interviewerMode= true;
        }else{
            //interviewerMode = Boolean.valueOf(ApexPages.currentPage().getParameters().get('interviewerMode'));
            interviewerMode = false;
        }
}
9
  • How can I set the Mode variable as false when I referesh the page. The Mode should be false since I need to show <apex:outputfield value="{!object.game}" rendered="{!NOT(Mode)}"/> when Mode=false and THIS - <apex:inputfield value="{!object__c.game}" rendered="{!Mode}"/> when Mode=true. Using return new pagereference('/'+recId); just refresh the page but the Mode becomes true again since I set it as true by default in constructor of extension
    – SfdcBat
    Commented Jun 3, 2016 at 5:07
  • @SfdcBat why you set this true by default? Commented Jun 3, 2016 at 5:25
  • When user first sees the page it should be in edit mode, So I set the Mode= true.
    – SfdcBat
    Commented Jun 3, 2016 at 5:26
  • I have copied full code of my VF and extension. Pls have a look
    – SfdcBat
    Commented Jun 3, 2016 at 5:28
  • @SfdcBat check my updated code. Commented Jun 3, 2016 at 5:29
1

Improving Tushar's Answer for your additional need. Return new Pagereference in below way:

return new pagereference('/apex/YourPageName?id='+recId+'&mode=false');

Then change your constructor as per below example:

constructor(){
    if(ApexPages.currentPage().getParameters().get('mode')=='false')
       mode=false;
    else
       mode=true;
     }

You must log in to answer this question.

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