You need to sign in to do that
Don't have an account?
Matt1000
Compile Error: Variable does not exist: queryResult at line 8 column 9
I tried to post this earlier, but I cannot locate the post. (Sorry if this is a duplicate.)
I am trying to compile an example from the following apex code documentation:
http://www.salesforce.com/us/developer/docs/apexcode/index_Left.htm#CSHID=apex_dynamic_soql.htm|StartTopic=Content%2Fapex_dynamic_soql.htm|SkinName=webhelp
I keep receiving the above compile error when trying to create the Apex class shown below (and on the web page path above).
CODE SAMPLE:
public class SOQLController {
public String name {
get { return name;}
set { name = value;}
}
public PageReference query() {
String queryName = '%' + name + '%';
queryResult = [SELECT Id FROM Contact WHERE
(IsDeleted = false and Name like :queryName)];
return null;
}
}
Thanks, Matt
queryResult = [SELECT Id FROM Contact WHERE (IsDeleted = false and Name like :queryName)];
From the above code you are trying to fetch the Contact records so first you need to create a List/Object instance of that type of Object means here is the Contact.
List<Contact> con = [SELECT Id FROM Contact WHERE (IsDeleted = false and Name like :queryName)];
OR simple contact instance if you put limit 1.
Contact con = [SELECT Id FROM Contact WHERE (IsDeleted = false and Name like :queryName) limit 1];
All Answers
queryResult = [SELECT Id FROM Contact WHERE (IsDeleted = false and Name like :queryName)];
From the above code you are trying to fetch the Contact records so first you need to create a List/Object instance of that type of Object means here is the Contact.
List<Contact> con = [SELECT Id FROM Contact WHERE (IsDeleted = false and Name like :queryName)];
OR simple contact instance if you put limit 1.
Contact con = [SELECT Id FROM Contact WHERE (IsDeleted = false and Name like :queryName) limit 1];
Yes. That did the trick. Thank you!
I guess the examples showed Java, but I need to convert this to Apex, which is new to me.
Thanks a lot!