0

I have implemented the following visualforce page on the lead layout: enter image description here

Here is the code:

    .hmk_top5table{

        color:black;
        width:99%;

        font-family:Arial, Helvetica, sans-serif;
        font-size:12px;
        padding:5px;

        background:white; 
        margin:5px;
        border:rgb(50,205,50) 1px solid;

        -moz-border-radius:5px;
        -webkit-border-radius:5px;
        border-radius:5px; 
    }

</style>
<apex:form >
<apex:pagemessages />
<apex:outputPanel id="hmk_panel_top5table" rendered="{!the_le_list!=null && the_le_list.size>0 && (the_lead.Leadevents_in_Bearbeitung_Counter__c > 0 || the_lead.Nicht_zugewiesene_Leadevents_Counter__c > 0) }">

    <table class="hmk_top5table"> 
        <tr>
            <th style="text-align:center;padding:5px;">Aktion</th>
            <th style="text-align:center;padding:5px;">Leadevent</th>
            <th style="text-align:center;padding:5px;">Phase</th>
            <th style="text-align:center;padding:5px;">Datum</th>
            <th style="text-align:center;padding:5px;">Fälligkeitsdatum</th>
            <th style="text-align:center;padding:5px;">Ungeöffnet</th>

        </tr> 

        <apex:variable var="ct" value="{!1}"/>
        <apex:repeat value="{!the_le_list}" var="sega" >
            <tr style="display: {!IF(sega.isClosed__c = true,'none','table-row')};"   > 

                <td style="text-align:center">


                   <apex:commandButton rendered="{!sega.Phase__c = 'Offen'}" disabled="{!sega.Leadevents_in_Bearbeitung_Counter_II__c > 0 && sega.Leadevents_nicht_zugewiesen_Counter__c > 0}" styleClass="btn" style="right:10px;position:relative;width:150px;" action="{!accept}" id="accept" value="Akzeptieren"/>
                   <apex:commandButton rendered="{!sega.Phase__c = 'Offen'}" styleClass="btn" style="width:150px;" action="{!decline}" id="decline" value="Ablehnen"/>
                   <apex:commandButton rendered="{!sega.Phase__c="in Bearbeitung" && sega.Leadevents_in_Bearbeitung_Counter_II__c > 0 && sega.Leadevents_nicht_zugewiesen_Counter__c > 0}" styleClass="btn" style="width:150px;" action="{!close}" id="close" value="Abschließen"/>

               </td>


                <td style="text-align:center">
                    <apex:outputLink style="color:{!IF(sega.Phase__c = 'in Bearbeitung','green','')}" target="_blank" value="{!URLFOR($Action.Leadevents__c.View, sega.Id, null)}">
                        <apex:outputtext value="{!sega.name}"/>
                    </apex:outputLink>          
                </td>


                <td style="text-align:center;color:{!IF(sega.Phase__c = 'in Bearbeitung','green','')}">
                    <apex:outputField value="{!sega.Phase__c}" /> 
                </td>

               <td style="text-align:center">
                    <apex:outputText value="{0,date,dd.MM.yyyy}" >
                        <apex:param value="{!sega.Datum_des_Leadevents__c}"/> 
                    </apex:outputText>

                </td>

                <td style="text-align:center;color:{!IF(sega.F_lligkeitsdatum__c < TODAY(),'red','')}">
                    <apex:outputText value="{0,date,dd.MM.yyyy}" >
                        <apex:param value="{!sega.F_lligkeitsdatum__c}"/> 
                    </apex:outputText>

                </td>

                <td style="text-align:center">

                <apex:inputCheckBox value="{!sega.Unge_ffnet_JR__c}"/>

                </td>

            </tr>
            <apex:variable var="ct" value="{!(ct+1)}"/>
        </apex:repeat>
    </table>        

</apex:outputPanel>

Here is my apex class code:

public with sharing class JTo_LeadeventOnLead {

public Lead the_lead {get; private set;} 

public Leadevents__c the_leadevent {get; private set;}

public string the_leadid {get; private set;}

public List<Leadevents__c> the_le_list {get; private set;}

public JTo_LeadeventOnLead(ApexPages.StandardController standardController) {

    the_leadid = standardController.getId(); 

    the_lead = [
                SELECT id, Name,Nicht_zugewiesene_Leadevents_Counter__c , Leadevents_in_Bearbeitung_Counter__c  
                FROM Lead
                WHERE id = : the_leadid
                LIMIT 1
              ];

    if(the_lead != null){

            the_le_list = [     
                                    SELECT Id, Name,F_lligkeitsdatum__c,Phase__c,Datum_des_Leadevents__c,Unge_ffnet_JR__c,isClosed__c,Leadevents_in_Bearbeitung_Counter_II__c,Leadevents_nicht_zugewiesen_Counter__c
                                    FROM Leadevents__c 
                                    WHERE Lead__c = : the_leadid
                                    Order by F_lligkeitsdatum__c DESC
                                    LIMIT 5
                              ];

    the_leadevent = [ 

                                    SELECT Id, Name,F_lligkeitsdatum__c,Phase__c,Datum_des_Leadevents__c,Unge_ffnet_JR__c,isClosed__c,Leadevents_in_Bearbeitung_Counter_II__c,Leadevents_nicht_zugewiesen_Counter__c
                                    FROM Leadevents__c 
                                    WHERE Lead__c = : the_leadid
                                    LIMIT 1
                                ];    

} }

public PageReference accept() {

for (Leadevents__c le : the_le_list) {
    le.Phase__c = 'in Bearbeitung';
}

update the_le_list;

return null;

} }

What happens? If I hit my custom commandbutton "accept" every entry in the list is getting updated and the visualforce page refreshes.

enter image description here

What should happen? Only the record where i hit the "Accept" - button should be updated and not only should the vf page refresh but the entire lead since I want the related lists - that include my custom object - to be up to date.

enter image description here

2
  • 1
    you need to pass the Id of the row where the button was clicked back to the controller. This requires use of apex:param and on the commandButton, rerender=. Then your controller can see which lead needs to be updated in the acton method
    – cropredy
    Jul 22, 2019 at 20:43
  • Hello @cropredy any chance you can help out with some code example? I added <apex:param name="id" value="{!sega.id}" assignto="{!leadevent}" /> on the visualforce page and public string leadevent {get; set;} on my class. But I struggle on using that now in my method.
    – Jan Tonnet
    Jul 23, 2019 at 18:04

1 Answer 1

0

A general approach to this is as follows. I didn't try and replicate your entire controller/page and instead focused on the essence, assuming that only one row's command button is clicked

Controller

public LeadEvents__c[] the_le_list {
   get { 
     return [SELECT ...
               FROM Leadevents__c 
               WHERE Lead__c = : this.stdCtrl.getId() // as stdCtrl, id will exist
               ... ];}
   set;
}

// indexed map of fetched leadevents. Used by accept Action Method
private Map<Id,LeadEvents__c> leadEventsById = new Map<Id,LeadEvents__c> (the_le_list);

private ApexPages.StandardController stdCtrl;
public Id selectedLeadEvent {get; set;}  // set by CommandButton

// Constructor should set properties that idempotent getters can use
public JTo_LeadeventOnLead(ApexPages.StandardController standardController) {
  this.stdCtlr = standardController;
}

/* action method accept() */
public PageReference accept() {
  LeadEvent__c selectedLeadEvent = leadEventsById.get(selectedId);
  selectedLeadEvent.Phase__c = 'in Bearbeitung';
  update selectedLeadEvent;
}

VF

...
<apex:repeat value="{!the_le_list}" var="sega" >
  <apex:commandButton rendered="..." action="{!accept}" id="accept" value="Akzeptieren"
    rerender="someDomId">  <!-- crucial - otherwise param won't be sent -->
     <apex:param value="{!sega.Id}" name="selectedLeadEvent"/>
  <apex:commandButton>
</apex:repeat>

BTW

  • Sobject LeadEvents__c should really be a singular name like LeadEvent__c as plural sobject name cause confusion

You must log in to answer this question.

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