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
SoulsSouls 

The hen and the egg - custom controller extension for Visualforce page

I have a custom object which is a child object to Case where the standard “Create New” method is overridden and points to a custom Visualforce page. I want to handle two use cases, the proper one selected based on a property in the parent case.

 

I want to get hold of the parent case number (through the master/child relationship) and with it do a SOQL query to get the value of a certain field in the case object and based on this value I want to render the correct part of the VF page. The rest of the form fields are empty at this stage, ready to be populated manually.

 

So, basically I want to render the VF page based on information that is not available (?) before the page is rendered it seems.

  

I have tried doing the lookup in the constructor of the controller or through the page’s action method but that all takes place before the page is populated and thus I don’t get a valid case number to use as an argument for my SOQL query. How to go about this?

 

/Mats

Prafull G.Prafull G.
You have to tweak controller code to identify the operations. Here are few points:
1. If the "New" button is clicked from custom tab of quick create then at this point you will not be having Case Number therefore you can probably go with steps i.e. show Lookup to select Case in first step and then Use the selected Case to perform the logic you want.
2. Second, You have to override the Related List button (New Custom object) as this time you have Case Number with you.

You have to add logic in your constructor to check whether to land on Step 1 (Select Case) or Directly perform logic (from related list and after Case Selection in Step 1) to render specific part of your VF page.

Let me know if it make sense!

Cheers!
SoulsSouls
Thank you for your answer crmtech.

I found my error, I was looking for a case number but what I had was the CaseID, though a case number is rendered on the page it is represented in the backend by the ID. What a noob mistake. Anyway thanks for your help.