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
XXXXXX 

Custom VF Button, Custom Controller?

Again, I think the answer is "No", but I want to make sure. I want to add a custom VF button to a standard layout. (I want this button to be conditional, and would have used an S-Control if they weren't going away.) I want to add this button to many different standard layouts. I want to use a custom controller with this button and, as far as I can tell by reading the doc, I cannot use a standard controller and a custom controller at the same time. Also from the doc, I am required to use a standard controller.

 

Please note that I want to use the SAME VF button on multiple layouts, including standard and custom objects.

 

Is this possible? And if this is possible, how can I do it?

 

TIA,

 

John

Best Answer chosen by Admin (Salesforce Developers) 
XXXXXX

This worked:

 

public class genericStdControllerExtension { private final SObject obj; public genericStdControllerExtension (ApexPages.StandardController cntrl) { this.obj = cntrl.getRecord(); } public String getId() { return 'Id: ' + obj.get('Id'); } public String getType() { return 'Type: ' + obj.getSObjectType(); } }

 

Now that I have the object ID and type, I can create programmatic relationships without having an underlying object relationship.

All Answers

jwetzlerjwetzler
Read the doc about extensions.  You can use extensions with a standard controller, which allows you to use any kind of custom logic that you want.
XXXXXX

OK, I tried that. Since I want to be able to extend ANY standard controller, I tried this:

 

public class genericStdControllerExtension { private final SObject obj; public genericStdControllerExtension (ApexPages.StandardController cntrl) { this.obj = cntrl.getRecord(); } public String getStdId() { return 'Id: ' + obj.id; } }

 

All I really want is the ID of the object. Once I have that, I can implement my custom logic and all's well.

 

Problem is, I get this error message:

 

Error: Compile Error: Field expression not allowed for generic SObject at line 13 column 27 

 

Is the error in my code, or am I trying to do something impossible?

 

TIA

 

John

XXXXXX

This worked:

 

public class genericStdControllerExtension { private final SObject obj; public genericStdControllerExtension (ApexPages.StandardController cntrl) { this.obj = cntrl.getRecord(); } public String getId() { return 'Id: ' + obj.get('Id'); } public String getType() { return 'Type: ' + obj.getSObjectType(); } }

 

Now that I have the object ID and type, I can create programmatic relationships without having an underlying object relationship.

This was selected as the best answer
CloudConversionCloudConversion

XXX,

 

What do your VisualForce pages look like in this case?

 

Is there anyway to have just one VisualForce page that is used on a Lead, Opportunity, Case, etc, but still leverage the data in their respective standard controllers?

 

Thanks,

Jon