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
Suzanne TimmerhansSuzanne Timmerhans 

Cannot get new fields into existing Controller

Trying to add new field to exisitng Apex Class that is Controller for a Visual Force page.  Although I added the field (custom field = Self_Direction__c) to the object (Account).  It is accepted under the section following the format of list of other fields  - void getAgencyRec(){ a = SELECT id, Self_Direction__c FROM account where id = :aIDLimit 1];
yet when I try to add it to the section followng the format of a list of other fields - public void saveAgencyRec() { aSaved.Self_Direction__c = app.Self_direction__c;  - I get an error message 
Error: Compile Error: Variable does not exist: Self_Direction__c at line 789 column 36  WHY???
Alain CabonAlain Cabon
You should copy/paste all your code because there is too much information missing to solve your problem.
Regards
Suzanne TimmerhansSuzanne Timmerhans
You asked for it - too much to post so I cut out areas that do not reference the field in question

public class IAC_Apply_Controller {

  public Application__c app { get; set; }
  public Account a { get; set; }
  public Account aSaved { get; set; }

  public Agency_Site__c HQSite { get; set; }
  public Agency_Site__c aSite { get; set; }
  public Agency_Site__c newSite { get; set; }
  List<Agency_Site__c> sites;
  
  public Contact newContact { get; set; }
  List<Contact> agencyContacts;   

  public Service__c newService { get; set; }
  public List< Service__c > services{ get; set; }  
  public List<  Subscribing_Member_Role__c > aRoleList{ get; set; }  

  public Opportunity newOpp { get; set; }
  public string warningMessage { get; set; }
  public class messageItem {
    public string mes { get; set; }
    public integer page { get; set; }
    public boolean isREP { get; set; }
    public messageItem( string m, integer p) {
      this.mes = m ;
      this.page = p;
    }
  }
  public list<messageItem> missingInfoMessageList { get; set; }
  public id aID { get; set; }
  
  String[] committeeList = new string[]{};
  public String[] getcommitteeList() {
    return committeeList;
  }
  public void setcommitteeList(String[] committeeList) {
    this.committeeList = committeeList;
  }  
  
  String[] ServedAgency = new string[]{};
  public String[] getServedAgency() {
    return ServedAgency;
  }
  public void setServedAgency(String[] ServedAgency) {
    this.ServedAgency = ServedAgency;
  }  

  String[] service = new string[]{};
  public String[] getService() {
    return service;
  }
  public void setService(String[] service) {
    this.service = service;
  }  

  public SelectOption[] SelectedServiceItems { get; set; }
  
  public integer step { get; set; }  
  public integer substep1 { get; set; }
  public integer substep2 { get; set; }
  public boolean NB_flag { get; set; }  // Next/Back Flag determines if next/back buttons will display 
  public RecordType rType { get; set; } 

  public string SiteID {get; set;}
  //public string whatAddUpdate {get; set;}  
  
  person per ;     

public class person {
    public contact p { get; set; }
    public boolean isCEO { get; set; }
    public boolean isREP { get; set; }
    public person( contact c, boolean CEO, boolean REP) {
      this.p = c ;
      this.isCEO = CEO;
      this.isREP = REP;
    }
  }
  
  // Constructor  - Initialize Values * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
  public IAC_Apply_Controller() {
    a = new Account();
    app = new Application__c();
    aSaved = new Account();
    aSite = new Agency_Site__c () ;
    newSite = new Agency_Site__c () ;
    newService = new Service__c();
    newContact = new Contact() ;
    newOpp = new Opportunity() ; 
    SelectedServiceItems = new List<SelectOption>();
    step = 0 ;
    rType = [SELECT id FROM RecordType WHERE name = 'New Membership' LIMIT 1 ] ;
    string iParam = ApexPages.currentPage().getParameters().get('id') ;
    if ( iParam != null ) {
      loadApp( iParam );
      if ( hasAppSubmitted( iParam )) step = 98 ;
    }
    setNB_flag() ;
  }
// Generic code called from all pages * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
   private void loadApp( string iParam ) {
     try{
       // Specify DML options to ensure the assignment rules are executed
       Database.DMLOptions dmlOpts = new Database.DMLOptions();
       dmlOpts.assignmentRuleHeader.useDefaultRule = true;
       aSaved.setOptions(dmlOpts);     
       aSaved = [
         SELECT  id, name, Agency_Website__c, Phone, ShippingStreet, ShippingCity, ShippingState,
           ShippingPostalCode, App_Individuals_Served__c, Fax, FTEs_Employed__c, Gross_Budget__c,
           Membership_Type__c, Gov_Certs_in_Good_Standing__c, Gov_Certs_Explanation__c, App_Year_of_Org__c, 
           App_Non_Profit__c, App_Legal_Purpose__c, BD_MEMS__c, AppContactName__c, 
           AppContactPhone__c, AppContactEmail__c, CEO__c, Primary_Contact__c, 
           Application_Status__c, ICF__c, CR__c, IRA_Supp__c, IRA_Supv__c, 
           DayTreat__c, PreVoc__c, SHELTWK__c, SEMP__c, DAY_HAB__c, MSC__c, ISS__c, FSS__c, FamCare__c, 
           ATHOME_RES__c, A16__c, A28__c, EI_ITIN__c, PSGroup__c, PSSEIT__c, ED853__c, 
           Respite__c, Recreation__c, Self_Direction__c, Other__c   
         FROM account WHERE id = : iParam LIMIT 1 ] ;
       aID = iParam ;
       app.name = aSaved.name ;
       app.Website__c = aSaved.Agency_Website__c ;
       app.Phone__c = aSaved.Phone ;
       app.BillingStreet__c = aSaved.ShippingStreet ;  
       app.BillingCity__c = aSaved.ShippingCity ;
       app.BillingState__c = aSaved.ShippingState ;
       app.BillingPostalCode__c = aSaved.ShippingPostalCode ;
       app.App_Individuals_Served__c = aSaved.App_Individuals_Served__c ;
       app.Fax__c = aSaved.Fax ;
       app.FTEs_Employed__c = aSaved.FTEs_Employed__c ;
       app.Gross_Budget__c = aSaved.Gross_Budget__c ;
       app.Membership_Type__c = aSaved.Membership_Type__c ;
       app.Gov_Certs_in_Good_Standing__c = aSaved.Gov_Certs_in_Good_Standing__c  ;
       app.Gov_Certs_Explanation__c = aSaved.Gov_Certs_Explanation__c ;
       app.App_Year_of_Org__c = aSaved.App_Year_of_Org__c ;
       app.App_Non_Profit__c = aSaved.App_Non_Profit__c ;
       app.App_Legal_Purpose__c = aSaved.App_Legal_Purpose__c ;
       app.BD_MEMS__c = aSaved.BD_MEMS__c ;
       app.AppContactName__c = aSaved.AppContactName__c ;
       app.AppContactPhone__c = aSaved.AppContactPhone__c ;
       app.AppContactEmail__c = aSaved.AppContactEmail__c ; 
     }
     catch (Exception e) {
       ApexPages.addMessages(e);
     }
   }

  

 
      } 
    }
    
    } 
  }
  public List<Service__c > getSiteServices() {  
    List<Service__c > sList = [
      SELECT
        name, 
        Agency_Name__c, 
        id, 
        Agency_Site__c,
        Capacity__c,
        Individuals_Served__c,
        Service_Type__r.name
      FROM Service__c 
      WHERE Agency_Site__c = :aSite.id ORDER BY Service_Type__r.name ASC ];
    services = slist ;  
    return sList;
  }

  public List<Agency_Site__c> getSites() {
    sites = [
      SELECT
        name, 
        id, 
        Agency__c,
        Street_Address__c,
        City__c,
        State__c,
        Zip_Postal_Code__c,
        Borough_County__c 
      FROM Agency_Site__c 
      WHERE Agency__c=: aid ];
    return sites;
  }

// This is used on page1 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
  public List< SelectOption > getAgencyOptions() {  
    set<id> arList = new set<id>();
    RecordType rt = [ SELECT id FROM RecordType WHERE name = 'Agency' AND SobjectType = 'Account' LIMIT 1 ] ;
    
    getARoleList() ;
    for( Subscribing_Member_Role__c a : ARoleList ) arList.add(a.Service_Consumer__c ) ;
    
    List<account > aList = [
      SELECT
        name, 
        id
      FROM account
      WHERE Active__c = TRUE AND 
        RecordTypeID = : rt.id AND 
        ( Membership_Type__c = 'REGULAR' OR Membership_Type__c = 'ASSOCIATE' OR Membership_Type__c = 'AFFILIATE' )
      ORDER BY name ASC ];
    List<SelectOption> options = new List<SelectOption>();
    for ( account a : aList ) if (! arList.contains(a.id)) options.add(new SelectOption(a.id,a.name)) ;
    return options;
  }
  
  public void getARoleList() {
    if ( aSaved != NULL ) {
      aRoleList = [
        SELECT id, name, Service_Consumer__r.name
        FROM Subscribing_Member_Role__c
        WHERE Service_Provider__c = : aSaved.ID
        ORDER BY Service_Consumer__r.name ASC ] ;
    }
    return ;
  
  }
  public PageReference addAgencyRole() {
    set<id> alist = new set<id>();
    Subscribing_Member_Role__c[] Roles2Add = new Subscribing_Member_Role__c[] {} ;
    
    for( Subscribing_Member_Role__c a : ARoleList ) alist.add(a.Service_Consumer__c ) ;
    
    for ( string a : ServedAgency ) {
      if ( ! aList.contains(a) ) {
        Roles2Add.add( new Subscribing_Member_Role__c ( Service_Provider__c = aSaved.id, Service_Consumer__c = a ) ) ;
      }
    }
    insert Roles2Add ;
    getARoleList() ;
    return null ;
  }



 
    getAgencyRec() ;
    return cID ;
    }
  
  void getAgencyRec() {
    a = [SELECT id, 
       Application_Status__c, name, Company_Name_from_Application__c, 
       Program_Name_s__c, Agency_Website__c, 
       AppContactName__c, AppContactPhone__c, AppContactEmail__c,
       Phone, Email__c, ShippingStreet, ShippingCity, ShippingState,
       ShippingPostalCode,  Fax, Membership_Type__c, Gov_Certs_in_Good_Standing__c, 
       Gov_Certs_Explanation__c, App_Year_of_Org__c, App_Non_Profit__c, App_Legal_Purpose__c, 
       App_Last_Step_Completed__c, Agency_Representative__c, CEO__c, Primary_Contact__c,
       App_OPWDD_All_Services__c, App_SED__c, App_SDOH__c, App_ACCES__c, App_LOCAL_ASSISTANCE__c,
       App_DDPC_GRANTS__c, App_MEDICAID_MEDICARE__c, FTEs_Employed__c, Gross_Budget__c, 
       BD_MEMS__c, App_Individuals_Served__c, App_1st_Yr_Opp__c, ICF__c, CR__c, IRA_Supp__c, IRA_Supv__c, 
       DayTreat__c, PreVoc__c, SHELTWK__c, SEMP__c, DAY_HAB__c, MSC__c, ISS__c, FSS__c, FamCare__c, 
       ATHOME_RES__c, A16__c, A28__c, EI_ITIN__c, PSGroup__c, PSSEIT__c, ED853__c, 
       Respite__c, Recreation__c, Self_Direction__c, Other__c, ICS__c
      FROM account where id =: aID LIMIT 1] ;
    }
  Public void saveAgencyRec() {
    aSaved.Application_Status__c = 'New' ;
    aSaved.name = app.name ;
    aSaved.Agency_Website__c  = app.Website__c ;
    aSaved.Phone = app.Phone__c ;
    aSaved.ShippingStreet = app.BillingStreet__c ;  
    aSaved.ShippingCity = app.BillingCity__c ;
    aSaved.ShippingState = app.BillingState__c ;
    aSaved.ShippingPostalCode = app.BillingPostalCode__c ;
    aSaved.App_Individuals_Served__c = app.App_Individuals_Served__c ;
    aSaved.Fax = app.Fax__c ;
    aSaved.FTEs_Employed__c = app.FTEs_Employed__c ;
    aSaved.Gross_Budget__c = app.Gross_Budget__c ;
    aSaved.Membership_Type__c = app.Membership_Type__c ;
    aSaved.Gov_Certs_in_Good_Standing__c = app.Gov_Certs_in_Good_Standing__c  ;
    aSaved.Gov_Certs_Explanation__c = app.Gov_Certs_Explanation__c ;
    if ( app.App_Year_of_Org__c != NULL && app.App_Year_of_Org__c.isNumeric() ) 
      aSaved.App_Year_of_Org__c = app.App_Year_of_Org__c ;
    else
      app.App_Year_of_Org__c = null;
    aSaved.App_Non_Profit__c = app.App_Non_Profit__c ;
    aSaved.App_Legal_Purpose__c = app.App_Legal_Purpose__c ;
    aSaved.BD_MEMS__c = app.BD_MEMS__c ;
    aSaved.AppContactName__c = app.AppContactName__c ;
    aSaved.AppContactPhone__c = app.AppContactPhone__c ;
    aSaved.AppContactEmail__c = app.AppContactEmail__c ; 
    aSaved.App_Last_Step_Completed__c = step;
    aSaved.ICF__c = app.ICF__c ;
    aSaved.CR__c = app.CR__c ; 
    aSaved.IRA_Supp__c = app.IRA_Supp__c ; 
    aSaved.IRA_Supv__c = app.IRA_Supv__c ; 
    aSaved.DayTreat__c = app.DayTreat__c ; 
    aSaved.PreVoc__c = app.PreVoc__c ; 
    aSaved.SHELTWK__c = app.SHELTWK__c ; 
    aSaved.SEMP__c = app.SEMP__c ; 
    aSaved.DAY_HAB__c = app.DAY_HAB__c ; 
    aSaved.MSC__c = app.MSC__c ; 
    aSaved.ISS__c = app.ISS__c ; 
    aSaved.FSS__c = app.FSS__c ; 
    aSaved.FamCare__c = app.FamCare__c ; 
    aSaved.ATHOME_RES__c = app.ATHOME_RES__c ; 
    aSaved.A16__c = app.A16__c ; 
    aSaved.A28__c = app.A28__c ; 
    aSaved.EI_ITIN__c = app.EI_ITIN__c ; 
    aSaved.PSGroup__c = app.PSGroup__c ; 
    aSaved.PSSEIT__c = app.PSSEIT__c ; 
    aSaved.ED853__c = app.ED853__c ; 
    aSaved.Respite__c = app.Respite__c ; 
    aSaved.Recreation__c = app.Recreation__c ; 
    aSaved.ICS__c = app.ICS__c ; 
    aSaved.Other__c = app.Other__c ; 
    aSaved.Self_Direction__c = app.Self_Direction__c;
      
    try{
      // Specify DML options to ensure the assignment rules are executed
      Database.DMLOptions dmlOpts = new Database.DMLOptions();
      dmlOpts.assignmentRuleHeader.useDefaultRule = true;
      aSaved.setOptions(dmlOpts);
      if ( aSaved.id  != NULL )  update aSaved ;  else {
        insert aSaved ;
        aID = aSaved.id ;
      }
    }
    catch (Exception e) {
      ApexPages.addMessages(e);
      step = 99 ; 
    } 
    getARoleList();  
  }
  


        }    







  
 
Alain CabonAlain Cabon
Ok, Error: Compile Error: Variable does not exist: Self_Direction__c at line 789 column 36  

means that the variable is not visible probably.
  • From the Developer Console (menu item under your name, at the top right): use the "Query Editor" tab:
          SELECT id, Self_Direction__c FROM account Limit 1

https://help.salesforce.com/articleView?id=code_dev_console_tab_query_editor.htm&type=0
  • if you cannot get a result for the request above, you should verify if this new field is visible for the main profiles.
        Edit your field and verify the visibility with the button "Set Field-Level Security".
 
Suzanne TimmerhansSuzanne Timmerhans
Thanks but I tried it and got nowhere – got no result from the “Query Editor” and the field is set as Visible for all profiles.
Suzanne TimmerhansSuzanne Timmerhans
Also checked my field access on my Profile - System Administrator - and I have read / edit rights for the new fields including Self_Direction__c.  ( I am experiencing the same messge / problem with all the new fields I have created on ACCOUNTS - even though they match existing like fields.
Alain CabonAlain Cabon
On Account and Application__c  ?

SELECT id, Self_Direction__c FROM Application__c Limit 1

 
Suzanne TimmerhansSuzanne Timmerhans
I found the problem - the fields exist in both Accounts and a custom Object Application.  The Controller was referencing the Custom Object and I had not created the fields in it.  Once I did that I was able to modify the Apex Class controller and Visual Force page!!!   And now that I am reading your last response - you saw it, too.  Its Application not just Account.  Thanks and sorry to waste you time on this but it's tough inheriting a set-up.
Alain CabonAlain Cabon
Good.
I could also find the problem because you have posted all the code. That's why it is important. 
And the fresh eyes can help too.
Regards.