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
KenAllredKenAllred 

Need help extending the opportunity controller to allow edit access to custom Account fields

Hello everyone -

 

I need to create a VF page that I can insert on my Opportunity Detail page layout that will contain custom fields for the Account object. This will allow our sales reps to edit/update these fields when they're working on an opportunity and also allow me to build some vaildation logic on the opportunity page to require that these Account fields are updated before they can move the opporutnity to the next stage in our sales process.

 

I understand that I need to extend the Opporunity controller in order to be able to do this. I've been searching for an example that I could work from (as I'm still learning Apex - only a few hours in), but I haven't been able to find anything.

 

Would anyone here be up to throwing together a quick example of extending the opportunity controller to access custom account fields to help me?

 

I'll also need to extend the Opportunity controller to access fields on some custom objects, but I'm thinking that once I get a good handle on how to do it with the Account object, I'll be able to do it with my custom objects.

 

Thanks for your help!

KenAllredKenAllred
Also, happy to pay for this help too. If you're interested in helping me with this, but would like to be compensated for your time. Shoot me a note along with what you would need to charge me for this at kallred@primary-intel.com.

Thanks!
KenAllredKenAllred

Okay, so I've been working at this problem myself and this is what I've come up with, but I'm stuck and could use some help.

 

I'm extending the Opportunity controller so that I can edit fields for the Account object associated with the currently selected Opportunity. I'll be creating a VF page that I can place on my Opportunity layout to allow our sales reps to edit these fields while they're working on the opportunity (versus having to switch to the Account detail page).

 

The first field that I'm attempting to get this working for is a custom field that is a multiselect picklist called "SFA__c" and is a list of SFA tools.

 

This is what I've put together for my extension class (but it's giving me an error):

 

public class opportunityExtension{
private final Opportunity o;
public opportunityExtension(ApexPages.StandardController stdController)
{
this.o = (Opportunity)stdController.getRecord();
}

public List<SelectOption> getSFA()
{
List<SelectOption> options = new List<SelectOption>();
Schema.DescribeFieldResult fieldResult = Opportunity.Account.SFA__c.getDescribe();
List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
for( Schema.PicklistEntry f : ple)
{
options.add(new SelectOption(f.getLabel(), f.getValue()));
}
return options;
}
}

 

This doesn't seem to like the way I'm referrencing my SFA__c field? i get the following error:

 

"Method does not exist or incorrect signature: Opportunity.Account.SFA__c.getDescribe()"

 

I then have a VF page with the following code that I'm using to test this:

 

<apex:page standardController="Opportunity" extension="opportunityExtension">

 

<apex:form >

<apex:pageBlock title="Edit Account Fields" mode="edit">
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!save}"/>
<apex:commandButton value="Cancel" action="{!cancel}"/>
</apex:pageBlockButtons>

 

<apex:selectList multiselect="true" size="9" value="{!SFA}" title="SFA Tool">
</apex:selectList>

</apex:pageBlock>
</apex:form>
</apex:page>

 

Can anyone help me with what I'm missing? Thank you!

 

- Ken