You need to sign in to do that
Don't have an account?
Custom button in Visualforce Page to update custom object
Dear Developers,
I have a custom object called Leadevents__c who is connected to Leads. There I have built several custom onclick javascript buttons. For example one button called "Accept" that - besides other stuff - changes a field called "Stage__c" on that custom object.
Now I don't want my users to work any longer from that object itself but to work from the standard lead object. I have built an APEX Class and a Visualforce Page to display the relevant information:
What I am trying to achieve is that my commandButtons on the visualforce behave the same way my custom javascript buttons do on the leadevents__c object.
So when I am on a Lead, that has a Leadevents__c record displayed in that visualforce page and I hit "Accept" the Stage__c of that very Leadevents__c record should change.
While I was able to display the buttons themselve I have little experience in APEX. So there is no code behind these buttons! It's just for showing what I want.
Here is my APEX Class so far:
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 sc) { the_leadid = sc.getId(); the_lead = [ SELECT id, Name, State, City, PostalCode, WirtschaftszweigWZ08__c,PLZ_erste_zwei_Ziffern__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 FROM Leadevents__c WHERE Lead__c = : the_leadid Order by F_lligkeitsdatum__c DESC LIMIT 5 ]; } } }Here 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="{!save}" id="accept" value="Akzeptieren"/> <apex:commandButton rendered="{!sega.Phase__c = 'Offen'}" styleClass="btn" style="width:150px;" action="{!cancel}" 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> </apex:page>