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
Sergio BeresuitaSergio Beresuita 

Method Void Error on Custom object

Hey everyone, Im fairly  new to APEX and need some guidance through this simple error. The error i receive is the Method void DeleteContact() is referenced by VisualForce page(cls) in salesforce.com. Remove the usage and try again.
This is pointing to the void DeleteInventory in the controller, so I am not sure what this error is exactly pointing.

cls page
<apex:page controller="clsController" sidebar="true" showheader="false" showChat="true" >

<html>
  <head>
    <title></title>
        <link href="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.2.2/css/bootstrap-combined.min.css" rel="stylesheet" 

media="screen"/>    

   <style>
      body {
        padding-top: 60px;
         }
     
    </style>
  </head>
  <body>
       <script src="http://code.jquery.com/jquery-latest.js"></script>
       <script src="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.2.2/js/bootstrap.min.js"></script>
    <div class="navbar navbar-inverse navbar-fixed-top">
      <div class="navbar-inner">
        <div class="container">
          <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </a>
          <a class="brand" href="#">Computer Inventory</a>
          <div class="nav-collapse collapse">
            <ul class="nav">
              <li class="active"><a href="#">Home</a></li>
              <li><a href="#about">About</a></li>
              <li><a href="#else">Contact</a></li>
            </ul>
          </div>        
          </div>
      </div>
    </div>

    <div class="container">



 <apex:form id="form">
<apex:image value="{!$Resource.LogoAbel}" width="30%" />
  <apex:pageBlock title="Computer Inventory">
  <apex:pageMessages >
</apex:pageMessages>
  <apex:pageBlockButtons >
          <apex:commandButton action="{!save}" value="Save"/>
  </apex:pageBlockButtons>
 <apex:pageBlock >
     <apex:panelgrid columns="2">
     <apex:selectList value="{!selectedField }" size="1">
     <apex:selectOption itemValue="Employee_Name__c" itemLabel="EmployeeName"/>
     <apex:selectOption itemValue="ASI_Solutions_Inventory_Number__c" itemLabel="ASI Solutions Inventory Number"/>
     <apex:selectOption itemValue="Location__c" itemLabel="Location"/>
     <apex:selectOption itemValue="Make__c" itemLabel="Make"/>
     <apex:selectOption itemValue="Model__c" itemLabel="Model"/>
     <apex:selectOption itemValue="Purchase_Date__c" itemLabel="Purchase Date"/>
     <apex:selectOption itemValue="Serial_Number__c" itemLabel="Serial Number"/>
     <apex:selectOption itemValue="Warranty__c" itemLabel="Warranty"/>
     <apex:selectOption itemValue="Vendor__c" itemLabel="Vendor"/>    
     </apex:selectList>
    <apex:commandButton value="Click Here to Sort" action="{!sortMethod}" reRender="pgblcktbl"/>
   </apex:panelgrid>
  </apex:pageBlock>
  <apex:pageBlock >
  
   <apex:pageblocktable value="{!inventories}" var="rec" id="pgblcktbl" >
  
   <apex:column >       
<apex:outputLink title="" value="/{!rec.id}/e?retURL=/apex/{!$CurrentPage.Name}" style="font-weight:bold">Edit</apex:outputLink>&nbsp;|&nbsp;       
<a href="javascript:if (window.confirm('Are you sure?')) DeleteInventory('{!rec.Id}');" style="font-weight:bold">Del</a>     
</apex:column> 
   
     <apex:column value="{!rec.Employee_Name__c}"/>
     <apex:column value="{!rec.ASI_Solutions_Inventory_Number__c}"/>
      <apex:column value="{!rec.Location__c}"/>
       <apex:column value="{!rec.Make__c}"/>
       <apex:column value="{!rec.Model__c}"/>
        <apex:column value="{!rec.Purchase_Date__c}"/>
        <apex:column value="{!rec.Serial_Number__c}"/>
        <apex:column value="{!rec.Warranty__c}"/>
        <apex:column headerValue="Vendor">
          <apex:inputField value="{!rec.Vendor__c}"/>
        </apex:column>   
  </apex:pageblocktable>
   
  
  </apex:pageBlock>
    
  </apex:pageBlock>
     <apex:actionFunction action="{!DeleteInventory}" name="DeleteInventory" reRender="form" >   
<apex:param name="inventoriesid" value="" assignTo="{!selectedField}"/>
</apex:actionFunction>
 
 </apex:form>
     </div> 
      </body>
</html>
</apex:page>



here is the controller
public with sharing class clsController 
{

    public List<Inventory__c> inventories {get;set;}
    public List<Inventory__c> con {get; set;}
    public string selectedField {get;set;}
    public clsController()
    {
    LoadData();
    }
       
    public void LoadData()
    { 
    
         inventories = [select Employee_Name__c, ASI_Solutions_Inventory_Number__c, Make__c, Model__c, Purchase_Date__c, Serial_Number__c,
        Vendor__c, Warranty__c, Location__c from inventory__c Limit 10];
     } 
    
   public void DeleteInventory()   {      
    
    if (SelectedField == null) 
    {      
    return;     
     }        
 Inventory__c tobeDeleted = null;     
  for(Inventory__c a: inventories)        
         if (a.Id == SelectedField) 
         {          
         tobeDeleted = a;  break;       
         }         
         
if (tobeDeleted != null) {      
 Delete tobeDeleted;      }          
         
         LoadData();   }       
          
            
  public void sortMethod()
  {
  if (selectedField =='Employee_Name__c')
  inventories = [select Employee_Name__c, ASI_Solutions_Inventory_Number__c, Make__c, Model__c, Purchase_Date__c, Serial_Number__c,
        Vendor__c, Warranty__c, Location__c from inventory__c where id IN:inventories order by Employee_Name__c Limit 10];
        
  else if(selectedField == 'ASI_Solutions_Inventory_Number__c') 
     inventories = [select Employee_Name__c, ASI_Solutions_Inventory_Number__c, Make__c, Model__c, Purchase_Date__c, Serial_Number__c,
        Vendor__c, Warranty__c, Location__c from inventory__c where id IN:inventories order by ASI_Solutions_Inventory_Number__c Limit 10];
        
 else if(selectedField ==  'Make__c') 
     inventories = [select Employee_Name__c, ASI_Solutions_Inventory_Number__c, Make__c, Model__c, Purchase_Date__c, Serial_Number__c,
        Vendor__c, Warranty__c, Location__c from inventory__c where id IN:inventories order by  Make__c Limit 10];
        
else if(selectedField == 'Model__c')
     inventories = [select Employee_Name__c, ASI_Solutions_Inventory_Number__c, Make__c, Model__c, Purchase_Date__c, Serial_Number__c,
        Vendor__c, Warranty__c, Location__c from inventory__c where id IN:inventories order by Model__c Limit 10];
        
else if(selectedField == 'Purchase_Date__c') 
     inventories = [select Employee_Name__c, ASI_Solutions_Inventory_Number__c, Make__c, Model__c, Purchase_Date__c, Serial_Number__c,
        Vendor__c, Warranty__c, Location__c from inventory__c where id IN:inventories order by Purchase_Date__c Limit 10];
        
else if(selectedField == 'Serial_Number__c') 
     inventories = [select Employee_Name__c, ASI_Solutions_Inventory_Number__c, Make__c, Model__c, Purchase_Date__c, Serial_Number__c,
        Vendor__c, Warranty__c, Location__c from inventory__c where id IN:inventories order by Serial_Number__c Limit 10];
       
else if(selectedField == 'Vendor__c') 
     inventories = [select Employee_Name__c, ASI_Solutions_Inventory_Number__c, Make__c, Model__c, Purchase_Date__c, Serial_Number__c,
        Vendor__c, Warranty__c, Location__c from inventory__c where id IN:inventories order by  Vendor__c Limit 10];
        
else if(selectedField == 'Warranty__c') 
     inventories = [select Employee_Name__c, ASI_Solutions_Inventory_Number__c, Make__c, Model__c, Purchase_Date__c, Serial_Number__c,
        Vendor__c, Warranty__c, Location__c from inventory__c where id IN:inventories order by Warranty__c Limit 10];
        
else if(selectedField ==  'Location__c') 
     inventories = [select Employee_Name__c, ASI_Solutions_Inventory_Number__c, Make__c, Model__c, Purchase_Date__c, Serial_Number__c,
        Vendor__c, Warranty__c, Location__c from inventory__c where id IN:inventories order by Location__c Limit 10];
  
  }
   
  public void save()
    {
    update inventories;
    }
    

}
thank you for any help

Best Answer chosen by Sergio Beresuita
Shyam BhundiaShyam Bhundia
Seems like the same visualforce page that  is referencing DeleteContact is also referencing LIST<Contact> contacts. 

If you have your source code in a IDE (e.g. eclipse) then do a search for DeleteContact in all your visualforce pages.

All Answers

Shyam BhundiaShyam Bhundia
Hi, 

Are you deleting a method called DeleteContact?  If so, it seems to be referenced by a visualforce page.
Sergio BeresuitaSergio Beresuita
No I am using the DeleteInventory method to delete a value from the custom object list Inventory.
I used to have DeleteContact method but I replaced it with DeleteInventory since I made new custom object and wasn't using the Contact List anymore.

It seems in the code that there is a DeleteContact method still there but I deleted it already so Im pretty confused to the error.
Shyam BhundiaShyam Bhundia
is the DeleteContact referenced in any other visualforce page?
Sergio BeresuitaSergio Beresuita
I have created other APEX pages that use the method DeleteContact.. Do you believe the problem is outside of the vf page cls and cls controller (both shown above)? I thought they would be independent... idk lol
Shyam BhundiaShyam Bhundia
so, if you have any visualforce pages where the controller is clsController and the page is referencing DeleteContact..it will cause the error you are facing.
Sergio BeresuitaSergio Beresuita
yeah that didnt seem to fix it.. .. hmmm im just confused to the problem.. thanks a lot though.. i will keep searching
Shyam BhundiaShyam Bhundia
hmm..try adding a method called  DeleteContact in your class for testing purpose.  If that gets rid of your error, then something must be referencing it.
Sergio BeresuitaSergio Beresuita
i tried that before and it gives me this error

 Error: clsController Compile Error: The property LIST<Contact> contacts is referenced by Visualforce Page (cls) in salesforce.com. Remove the usage and try again. at line 3 column 26

basically telling me to swich from the custom object list (inventory) to the list contact.

this code was used at beginning to reference only Contact list but i decided to make an Inventory with similar values except different list. It seems in the apex that it still thinks  the code is at Contact.... or unless the DeleteContact method is a set method only for the contacts list...
Shyam BhundiaShyam Bhundia
Seems like the same visualforce page that  is referencing DeleteContact is also referencing LIST<Contact> contacts. 

If you have your source code in a IDE (e.g. eclipse) then do a search for DeleteContact in all your visualforce pages.
This was selected as the best answer
Sergio BeresuitaSergio Beresuita
So while I looked through the apex code today, I clicked next to the console where it says "Where is this used?" and to my surprise it still said Contact List, so
apparently Visual Force doesnt let you swicth through a lot of code at the same time, as it keeps methods and values and references. So what I did was create a whole new complete vf page and then just put the code in there, so now the code works. thanks for the help! though, it gave me a difference way of thinking