You need to sign in to do that
Don't have an account?
Michael Clarke 36
My first controller extension
Hi, I am learning skills as a developer and I have a use case for what I have learnt.
The Case object has parent Opportunity, and the Opportunity object has children Opportunity_Split__c.
I would like to show Opportunity Splits on the Case page using the Lightning App Builder.
My understanding is that for a visualforce page to appear on a Case Page it needs to utilise the Case standard controller. Therefore I need to extend the standard controller with an extension.
Visualforce code is:
Am I anywhere near a solution or is my understanding way off the mark?
Your help in solving this, and expanding my knowledge, would be very much appreciated.
The Case object has parent Opportunity, and the Opportunity object has children Opportunity_Split__c.
I would like to show Opportunity Splits on the Case page using the Lightning App Builder.
My understanding is that for a visualforce page to appear on a Case Page it needs to utilise the Case standard controller. Therefore I need to extend the standard controller with an extension.
Visualforce code is:
<apex:page standardController="Case" extensions="Case_ListOppSplits_Controller" lightningStylesheets="true"> <apex:pageBlock title="Opportunity Splits"> <apex:pageBlockTable value="{!Opportunity_Splits}" var="oppSplit"> <apex:column value="{!oppSplit.Name}"/> <apex:column value="{!oppSplit.Split_Loan_Amount__c}"/> <apex:column value="{!oppSplit.Rate_Type__c}"/> <apex:column value="{!oppSplit.Repayment_Type__c}"/> </apex:pageBlockTable> </apex:pageBlock> </apex:page>Case Controller extension is:
public class Case_ListOppSplits_Controller { public ApexPages.StandardSetController setController{ get{ if(setController==NULL){ Case currentCase = [SELECT Id, Subject, Opportunity__c FROM Case WHERE Id =: ApexPages.currentPage().getParameters().get('id')]; setController = new ApexPages.StandardSetController(Database.getQueryLocator( [SELECT Id, Name, Opportunity__c, Loan_Purpose__c, Loan_Type__c, Loan_Usage__c, Rate_Type__c, Repayment_Type__c, Split_Loan_Amount__c FROM Opportunity_Split__c WHERE Opportunity__c =: currentCase.Opportunity__c])); } return setController; } set; } //initialise setController and return a list of records public list<Opportunity_Split__c> getOpportunity_Splits(){ return (List<Opportunity_Split__c>) setController.getRecords(); } }The visualforce page cannot be saved as it throws this error: Unknown constructor 'Case_ListOppSplits_Controller.Case_ListOppSplits_Controller(ApexPages.StandardController controller)'
Am I anywhere near a solution or is my understanding way off the mark?
Your help in solving this, and expanding my knowledge, would be very much appreciated.
It appears that this isn't actually a custom controller, but rather a controller extension. You should be using the below If you don't need standard controller functionality.
If you're really trying to write a controller extension, then your extension needs to have a constructor that takes an argument of ApexPages.StandardSetController.
If you find this information helpful, please mark this answer as Best. It may help others in the community. Thank You!
Anudeep
Based on your answer I think I need a standard controller and controller extension.
I have to have standardController = 'Case' because I want to place the vf page on the Case record page. (That is my understanding)
I believe I need a standard controller extension to bring through the Opp Splits data.
So how would I incorporate your code into mine?