I have a button that was created to allow a user to schedule an appointment with a lead. The button goes to an external schedular and should pull in the details of the lead (name, email, and phone) into the schedular form, thus allowing the user to just select a time and complete the form for the appointment.
I have a formula field (test__c) on the lead object that combines a field from the user (this field houses the user's specific calendar URL) and appends text of the remaining part of the URL that I need to pull in data for the form.
Formula field (test__c):
$User.Calendar__c + "?soSkip=1&sosfLeadId=Lead.Id&sosfContactId=Contact.Id&sosfCaseId=Case.Id"
The apex class that is used in VF page for the button allows for the use of the formula field and goes to the external form but for some reason is not pulling in the data from the lead that the button was clicked from.
Apex class:
public class CalendarApexClass {
Lead record;
public PageReference urlRedirection() {
string url = record.Test__c;
PageReference page = new PageReference(url);
page.setRedirect(true);
return page;
}
public CalendarApexClass(ApexPages.StandardController stdController) {
if(!Test.isRunningTest()) {
stdController.addFields(new String[] { 'Test__c' });
}
record = (Lead)stdController.getRecord();
}
}
Normally I would just use the URL option on the button but when I use the field formula test__c it does not open an external tab and throws the error that Lightening cannot load the page. So instead I created a VF page (see code for VF page below) to call the apex class. The external page loads fine but it does not pull in the data from the lead even though the URL text is designed to do just that. I am assuming something is happening with the apex class to prevent this but I am not knowledgeable enough to pinpoint what that is. Any help would be awesome!
VF page:
<apex:page StandardController="lead" extensions="CalendlyApexClass" action="{!urlRedirection}" >
</apex:page>
with sharinginto my public class at the top and still ran into the same issue so not sure if this is user error on my part because I am new or if this isn't the right solution. – twolfe Nov 15 '23 at 19:45