I am trying to update fields on a custom object using visualforce. I have embedded a visualforce page on Lead Layout that displays records of my custom object linked to the lead. I want to update fields on these records when hitting the buttons- I dont' want to update the Lead.

What should happen? When clicking on "Accept" (Akzeptieren) the field "Stage__c" (Status) on my custom object should change it's value. I am not to familiar with apex and I can't get my head around how to access my custom object and not the lead which is my standardController since this is where the Visualforce Page should be seen?!

enter image description here

Here is my VF Page:

<apex:page standardController="Lead" extensions="JTo_LeadeventOnLead" tabStyle="Lead" showHeader="false" sidebar="false" >



        font-family:Arial, Helvetica, sans-serif;

        border:rgb(50,205,50) 1px solid;



<apex:pagemessages />
<apex:outputPanel id="hmk_panel_top5table" rendered="{!the_le_list!=null && the_le_list.size>0}">

    <table class="hmk_top5table"> 
            <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>


        <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:form >

                   <apex:commandButton rendered="{!sega.Phase__c = 'Offen'}" styleClass="btn" style="right:10px;position:relative;width:150px;" action="{!edit}" id="accept" value="Akzeptieren"/>
                   <apex:commandButton rendered="{!sega.Phase__c = 'Offen'}" styleClass="btn" style="width:150px;" action="{!edit}" id="decline" value="Ablehnen"/>


                <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}"/>

                <td style="text-align:center">
                    <apex:outputField value="{!sega.Phase__c}" /> 

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


                <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}"/> 


                <td style="text-align:center">
                <apex:form >
                <apex:inputCheckBox value="{!sega.Unge_ffnet_JR__c}"/>

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


The buttons have no code behind them. Right now they are just for visualization and run with the salesforce default action "!edit" which when you hit the button will edit the lead.

Here is my apex class that fills my Visualforce Page with life:

public with sharing class JTo_LeadeventOnLead {

    public Lead the_lead {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 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   
                FROM Leadevents__c 
                WHERE Lead__c = : the_leadid
                Order by F_lligkeitsdatum__c DESC
                LIMIT 5

1 Answer 1


Best to move the apex:form right out to just inside the apex:page as one form per page is the normal approach.

Then define and call a separate method in your exctension controller for each button e.g.:

<apex:commandButton action="{!accept}" value="Akzeptieren" ... />


public PageReference accept() {

    for (Leadevents__c le : the_le_list) {
        le.Stage__c = le.Unge_ffnet_JR__c ? 'Checked value' : 'Unchecked value';
    update the_le_list;

    return null;

This is the idea of controller extensions: you add your own methods in the extension where necessary and call the methods of the standard controller where appropriate.

  • Hello @Keith C, Thanks for your reply. I managed to get the apex:form to top and bottom of my vf page. The method works so far and it really opened my eyes here on how to achieve this in the future. However, now when I hit "Accept", the entire list of records gets updated and not only the one record where I hit "Accept". I would need to go record per record. And can we achieve to refresh the Lead page as final step? Thanks again! –
    – Jan Tonnet
    Jul 23, 2019 at 19:10

You must log in to answer this question.

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