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
Laurie DrewLaurie Drew 

Help with query


Hi I am new to SOQL and trying to write a query on the account object that will return a count of the number of records that have been edited in the last 7 days.

I tried this code but get error on compile Illegal assignment from integer to list

public with sharing class TestDisplayQueryList{ 
public List<Account> Records {get; set;} 
public TestDisplayQueryList(){ 
Records = 
[select count() from account where LastModifiedDate = LAST_N_DAYS:7]; 

}

Any help would be greatly appreciated! 
Best Answer chosen by Laurie Drew
Eric PepinEric Pepin
public with sharing class TestDisplayQueryList {
	public integer NumOfAccounts { get; set; } 

	public TestDisplayQueryList() {
		NumOfAccounts = [SELECT COUNT() FROM Account WHERE LastModifiedDate = LAST_N_DAYS:7];
	}
}

All Answers

Eric PepinEric Pepin
public with sharing class TestDisplayQueryList {
	public integer NumOfAccounts { get; set; } 

	public TestDisplayQueryList() {
		NumOfAccounts = [SELECT COUNT() FROM Account WHERE LastModifiedDate = LAST_N_DAYS:7];
	}
}
This was selected as the best answer
HARSHIL U PARIKHHARSHIL U PARIKH
You need to store the records returned from query inside the SObject list.
Something of this nature
 
List<Account> allActs = [Select Id, Name FROM Account WHERE LastModifiedDate = LAST_N_DAYS:7];
I am not sure if you can use * in SOQL though..
 
Laurie DrewLaurie Drew
Thank you Eric, works perfectly!