function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Janno RipJanno Rip 

Custom apex: commandLink - action = {!triggerMyCustomButtonLogic}

Hello everyone,

I have the following custom button (Akzeptieren / Accept) on detail view on my custom object leadevents__c:


User-added image

On top of that I build a custom related list (visualforce) for my custom object on the account view:


User-added image

Here also, i want to implement the logic of my button so whenever I click the Accept / Decline Button in the related List I want to trigger the logic of my custom detail page button. I achieved editing the "action button" inside my visualforce page:

<apex:commandLink value="Akzeptieren" style="color:#015ba7;" 
action="{!editLeadevents}" target="_parent" ><apex:param value="{!le.id}" name="LeadeventsId"/> </apex:commandLink> 

As one can see the "action" is {!editLeadevents} which is a standard action!? What I want is to call my very own action / button "Akzeptieren"

Here is the code from the java script onclick button on the detail page:

{!REQUIRESCRIPT("/soap/ajax/41.0/connection.js")} 

try{ 
var LeadeventObj = new sforce.SObject("Leadevents__c"); 
LeadeventObj.Id = "{!Leadevents__c.Id}"; 

if("{!Leadevents__c.OwnerId}" != "{!$User.Id}")

alert("Nicht ausreichend Berechtigung."); 

else if ({!Leadevents__c.Leadevents_in_Bearbeitung_Counter_II__c} > 0)
{
alert("Es ist bereits ein Leadevent in Bearbeitung.");
}
else if("{!Leadevents__c.AccountId__c}" == '')

LeadeventObj.RecordTypeId = "0121l0000008XPt";
LeadeventObj.Status__c = "Akzeptiert";
LeadeventObj.Phase__c = "in Bearbeitung"; 

var updateResult = sforce.connection.update([LeadeventObj]); 
if(updateResult[0].success === "true"){ 
location.reload(); 
}
}
else 
{
LeadeventObj.RecordTypeId = "0121l0000008XPe";
LeadeventObj.Status__c = "Akzeptiert";
LeadeventObj.Phase__c = "in Bearbeitung"; 


Here is the part of my controller that is resonsible for the "editing" functionality:


    //This method is to edit the existing leadevent records while clicking the Edit link 

    public pageReference editLeadevents(){  

        String LeadeventsId = Apexpages.currentpage().getParameters().get('LeadeventsId');  

        pageReference pageRef = new pageReference(URL.getSalesforceBaseUrl().toExternalForm() + '/' + LeadeventsId + '/e?retURL=' + Leadevents__c.id);  

        return pageRef;  


So what I want is to click on the "Akzeptieren" CommandLink inside my custom related list and to execute the logic of the javascript onclick button. Pretty sure this is possible

Thanks in Advance and Greetings