Can you not query the same object more than once in a single class? I have a class that I grab information related to the Contract Member record to create a list of Contracts. I want to also create a function within the class that I use to grab the hourly rate of the Contract Member and use it to set a total cost field on the visual force page.
It seems that any time I want to query the same object (in this case the end where I am trying to assign a value to the variable hourly), I get an error that says
Error: Compile Error: Illegal assignment from List to Integer at line 24 column 8
Here is the Apex Code. I am new to Apex but it would be really ridiculous if you have to have multiple extensions to work with the same object.
public with sharing class addMultipleCostsExtension {
public list<Contract_Cost__c> listCost{get;set;}
public String selectedContractMember{get;set;}
public addMultipleCostsExtension(ApexPages.StandardController controller) {
listCost= new list< Contract_Cost__c >();
}
public List<selectOption> getContractMembers() {
List<SelectOption> ContractMembers=new List<SelectOption>();
ContractMembers.add(new SelectOption('0001', '--Select--'));
List<Contract_Member__c> ContractMembersList=[SELECT Id, Name, CES_Contract__r.Name, CES_Contract__c FROM Contract_Member__c WHERE Internal_Employee__c =:UserInfo.getUserId()];
for(Contract_Member__c r:ContractMembersList) {
ContractMembers.add(new SelectOption(r.ID,r.CES_Contract__r.Name));
}
return ContractMembers;
}
public integer hours{get;set;}
public integer totalCost{get;set;}
public integer hourlyRate{get;set;}
public void setCost(){
hourlyRate = [SELECT Hourly_Rate__c FROM Contract_Member__c WHERE Internal_Employee__c =:UserInfo.getUserId()];
totalCost = hours*hourlyRate;
}
It seems that the object name is being used in the List, which yeah I guess it is but (again new at this) it seems that you need to include the object name in the List definition <> in order for it to work. Maybe the List needs to just be renamed.