1

I get the following error when trying to save the controller for a Contacts visualforce page:

Error: My_Contacts Compile Error: The property List contacts is referenced by Visualforce Page (mycontacts) in salesforce.com. Remove the usage and try again. at line 9 column 26

I'm not sure what's causing this error. I think I'm instantiating the constructor correctly. Am I missing something, or are the pagination methods I have in the controller messing things up for some reason?

Here is the Visualforce page code:

    <apex:page controller="My_Contacts" tabStyle="Contact" sidebar="false" readOnly="true" cache="false" id="thePage">
    <html xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" lang="en">
   <head>
   <meta charset="utf-8" />
   <meta http-equiv="x-ua-compatible" content="ie=edge" />
   <title>My Contacts</title>
   <meta name="viewport" content="width=device-width, initial-scale=1" />
   <apex:stylesheet value="{!URLFOR($Resource.SLDS214, 'assets/styles/salesforce-lightning-design-system-vf.min.css')}" />
    </head>
   <body>

<!-- REQUIRED SLDS WRAPPER -->
<div class="vcc">

<!-- MASTHEAD -->

<!-- / MASTHEAD -->
<!-- PAGE HEADER -->
<div class="slds-page-header" role="banner">
<div class="slds-grid">
<div class="slds-col slds-has-flexi-truncate">
  <!-- HEADING AREA -->
  <p class="slds-text-title--caps slds-line-height--reset">Contacts</p>
  <h1 class="slds-page-header__title slds-truncate" title="My Contacts">My Contacts</h1>
  <!-- / HEADING AREA -->
</div>
<div class="slds-col slds-no-flex slds-grid slds-align-top">
  <button class="slds-button slds-button--neutral">
  <apex:outputLink value="{!URLFOR($Action.Contact.NewContact)}">New Contact
  </apex:outputLink></button>
 </div>
 </div>

</div>
<!-- / PAGE HEADER -->
<!-- PRIMARY CONTENT WRAPPER -->
<div class="myapp">

    <apex:form id="theForm" >
    <apex:pageBlock >
    <!-- <apex:pageBlockButtons >             
        <apex:commandButton action="{!Beginning}" title="Beginning" value="First" disabled="{!disablePrevious}" reRender="con_table"/>
        <apex:commandButton action="{!Previous}" title="Previous" value="Previous" disabled="{!disablePrevious}" reRender="con_table"/>        
        <apex:commandButton action="{!Next}" title="Next" value="Next" disabled="{!disableNext}" reRender="con_table"/>
        <apex:commandButton action="{!End}" title="End" value="Last" disabled="{!disableNext}" reRender="con_table"/>     
     </apex:pageBlockButtons> -->

        <apex:pageMessages />
            <div align="center">
            <div class="slds-grid slds-wrap slds-grid--pull-padded">
            <div class="slds-col slds-size--1-of-3 slds-small-size--1-of-2 slds-medium-size--1-of-4">
            <div align="left" class="slds-form-element__label">
                &nbsp;<apex:outputLabel value=" View: " /> 

                 <!-- <apex:selectList value="{!filterId}" size="1">
                    <apex:actionSupport event="onchange" rerender="con_table"/>
                    <apex:selectOptions value="{!listviewoptions}"/>
                </apex:selectList> -->


            </div>
            </div>
            <div class="slds-col slds-size--1-of-1">
            <div class="slds-form-element__label slds-align--left slds-text-body--regular"> 
               <apex:commandLink action="{!previous}">&nbsp;Previous</apex:commandlink>
               &nbsp;|&nbsp; 
               <apex:commandLink action="{!next}">Next</apex:commandlink>  
               <p>&nbsp;</p>        
            </div>
            </div>

            </div>


        <apex:pageBlockTable value="{!contacts}" var="con" id="con_table">
            <apex:column >
                <apex:facet name="header">Name</apex:facet>
                <apex:outputLink value="{!URLFOR($Action.Contact.View, con.id)}">{!con.name}</apex:outputLink>
                </apex:column>
            <apex:column >
                 <apex:facet name="header">Organization</apex:facet>
                <apex:outputlink value="{!URLFOR($Action.Account.View, con.account.id)}">{!con.account.name}</apex:outputlink>
                </apex:column>
            <apex:column value="{!con.Title}"/>
            <apex:column value="{!con.Email}"/>
            <apex:column value="{!con.Phone}"/>
        </apex:pageBlockTable>


 </div>    

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

</div>
</div>
</body>
</html>

And here's the controller:

public with sharing class My_Contacts {

    String userId = UserInfo.getUserId();
    private string sortExp = 'LastName';
    private string sortDirection = 'ASC';
    private integer counter=0;  //keeps track of the offset
    private integer list_size=20; //sets the page size or number of rows
    public integer total_size;

    public ApexPages.StandardSetController setCon {
        get {
            if(setCon == null) {
                setCon = new ApexPages.StandardSetController(Database.getQueryLocator(
                    [select Name, Title,contact.account.name, Phone, Email, owner.id 
                    from contact 
                    where owner.id =: userId 
                    order by lastName
                    limit :list_size 
                    offset :counter]));
                total_size = [select count() from Contact where owner.id =: userId]; //set the total size in the constructor
            }
            return setCon;
        }
        set;
    }


   public List<Contact> getContacts() {
      return (List<Contact>) setCon.getRecords();
   }


   public PageReference Beginning() { //user clicked beginning
      counter = 0;
      return null;
   }

   public PageReference Previous() { //user clicked previous button
      counter -= list_size;
      return null;
   }

   public PageReference Next() { //user clicked next button
      counter += list_size;
      return null;
   }

   public PageReference End() { //user clicked end
      counter = total_size - math.mod(total_size, list_size);
      return null;
   }

   public Boolean getDisablePrevious() { 
      //this will disable the previous and beginning buttons
      if (counter>0){ 
          return false;
      } else {
          return true;
      }
   }

   public Boolean getDisableNext() { //this will disable the next and end buttons
      if (counter + list_size < total_size) return false; else return true;
   }

   public Integer getTotal_size() {
      return total_size;
   }

   public Integer getPageNumber() {
      return counter/list_size + 1;
   }

   public Integer getTotalPages() {
      if (math.mod(total_size, list_size) > 0) {
         return total_size/list_size + 1;
      } else {
         return (total_size/list_size);
      }
   }
}

1 Answer 1

3

The error basically says that you are trying to reply a change to the controller and that change cannot be made because it is being used on an existing VF page.

I saved your class and then save the page exactly as you have it and it worked fine.

It is an order of operations thing.

Suggest you:

  1. Save the VF page
  2. Then save your class

If that does not work, delete the page and class then:

  1. Save your class
  2. Save your page

Since your code as you have it in your question compiles the issue is how your are saving/deploying it.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .