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
ElcalvoMikeElcalvoMike 

Controller problems for APEX class

I cannot figure out how to reference variables from the controller initiated in the constructor.

I get Variable does not exist: opp.fname__c. However this is the name of this custom field.

Am i not calling this correctly?

 

public class MailClass {
private final Opportunity opp;
public mailClass(ApexPages.StandardController controller)
{
this.opp=(Opportunity)controller.getRecord();
}

static final string Subject='Hi ' + opp.fname__c;

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
jeremyyjeremyy

With

static final string Subject='Hi ' + opp.fname__c;

 you're intializing a static variable by trying to reference an instance field. You can't do this. Are you sure you want Subject to be static?

All Answers

jeremyyjeremyy

With

static final string Subject='Hi ' + opp.fname__c;

 you're intializing a static variable by trying to reference an instance field. You can't do this. Are you sure you want Subject to be static?

This was selected as the best answer
ElcalvoMikeElcalvoMike

This string will be used in a later function in this class that creates a dynamic HTML email.

I tried changing the delaration to private/public and just string. No luck...what do I set it to?

ElcalvoMikeElcalvoMike

Oh I got it. Set to just string and it did the trick! Thanks for the direction.