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?!
Here is my VF Page:
<apex:page standardController="Lead" extensions="JTo_LeadeventOnLead" tabStyle="Lead" showHeader="false" sidebar="false" >
<style>
.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:pagemessages />
<apex:outputPanel id="hmk_panel_top5table" rendered="{!the_le_list!=null && the_le_list.size>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: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"/>
</apex:form>
</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">
<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:form >
<apex:inputCheckBox value="{!sega.Unge_ffnet_JR__c}"/>
</apex:form>
</td>
</tr>
<apex:variable var="ct" value="{!(ct+1)}"/>
</apex:repeat>
</table>
</apex:outputPanel>
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
];
}
}
}