0

that's my second question today , i am new to salesforce and i am facing problems every day.

I am iterating through a map as indicated in this visualforce code:

<apex:repeat value="{!map_condidat_cv}" var="key" >
    <tr>
        <td><apex:outputField value="{!map_condidat_cv[key].Nom__c}"/></td>
        <td><apex:outputField value="{!map_condidat_cv[key].Email__c}"/></td>
        <td><apex:outputField value="{!map_condidat_cv[key].Adresse__c}"/></td>
        <td><apex:inputField value="{!map_condidat_cv[key].Motif_de_Refus__c}"/></td>
        <td><apex:commandButton styleClass="btn btn-primary" value="Voir le CV" action="/servlet/servlet.FileDownload?file={!key.id}" /></td>
        <td><button type="button" class="btn btn-primary">Le status suivant</button></td>
        <td>
            <apex:commandButton styleClass="btn btn-primary" action="{!valider}" value="Valider" rerender="none">      
                <apex:param name="condidatID" value="{!map_condidat_cv[key].id}" assignTo="{!condidatID}"/>
            </apex:commandButton>

the field <td><apex:inputField value="{!map_condidat_cv[key].Motif_de_Refus__c}"/></td> is a pick list field where the user can choose among many options.

What I want is that when the user chooses an option and clicks on the button "valider", this field get updated in the database. I tried to do that but I get always the default option (the one that existed before clicking on the button).

here is the apex code

public PageReference valider(){
    // here i am testing if the value changed or not 
    Candidat_p__c testing = [select id,Adresse__c, Email__c,Nom__c,Motif_de_Refus__c,mobile_teste__c,Code_Postal__c from Candidat_p__c where id =:this.condidatID];
    motif_de_refus = testing.Motif_de_Refus__c;
    Pagereference home = new PageReference('https://c.eu2.visual.force.com/apex/Portail_agence?id='+this.condidatID+'&mo='+motif_de_refus);                 
    home.setRedirect(true);  
    return home;
}

I edited the code, i added this line in order to pass the picklist option chosen by the user as a parameter <apex:param name="motifRefus" value="{!map_condidat_cv[key].Motif_de_Refus__c}" assignTo="{!motif_de_refus}"/> inside the commandButton but it sends always the old option .

5
  • you need to perform DML to commit data into database.. – Ratan Paul Feb 21 '16 at 16:40
  • why , i think the field {!map_condidat_cv[key].Motif_de_Refus__c} is related to the database , isn't ? – Merabti Ibrahim Feb 21 '16 at 16:45
  • map_condidat_cv is just a variable in order to commit updated data to database you need to perform DML. THen only when you perform query it will return saved data from database. – Ratan Paul Feb 21 '16 at 16:47
  • i tried that but i get always a null value <apex:param name="motifDeRefus" value="{!map_condidat_cv[key].Motif_de_Refus__c}" assignTo="{!motifDeRefus}"/> – Merabti Ibrahim Feb 21 '16 at 16:58
  • why you are using apex:param no need.. In controller put a debug in valider method and check this map map_condidat_cv and Motif_de_Refus__c field.. – Ratan Paul Feb 21 '16 at 17:01
0

Possibly you need to apply some DML to your record, e.g.:

if (testing.Motif_de_Refus__c != map_condidat_cv[key].Motif_de_Refus__c) {
    testing.Motif_de_Refus__c = map_condidat_cv[key].Motif_de_Refus__c;
    update testing;
}

...and then rerender whatever block contains your repeat when clicking that apex:commandButton.

Take a look the example of a page using a controller called ListsMapsController.

Here's a gist that demonstrates how controller variables get updated and how changes get pushed back to a VisualForce page on rerender: force.com: update variables.

9
  • i agree with you, but i have tried to pass it as a parameter as you said but i get always a null value because the table is created automatically by the repeat tag and each row has this peice of code value="{!map_condidat_cv[key].Motif_de_Refus__c}" assignTo="{!motifDeRefus}" ,in other words i am trying to assign many inputs to the same variable and i do not know how to overcome that . – Merabti Ibrahim Feb 21 '16 at 16:57
  • @MerabtiIbrahim, I removed the apex:param bit. Can you verify if the modified answer works as expected? – tobibeer Feb 21 '16 at 17:04
  • Also there should be a try/catch, and you need to return a null PageReference if you want it to not redirect. – Adrian Larson Feb 21 '16 at 17:08
  • @tobibeer do you mean this code if (testing.Motif_de_Refus__c != map_condidat_cv[key].Motif_de_Refus__c) { testing.Motif_de_Refus__c = map_condidat_cv[key].Motif_de_Refus__c; update testing; } – Merabti Ibrahim Feb 21 '16 at 17:10
  • @MerabtiIbrahim yes, that and, most importantly, the DML update statement being triggered. Atm, I'm not sure that binding your apex components to a map actually pushes edits back to the map in your controller. – tobibeer Feb 21 '16 at 17:41

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.