I have a method that takes account id as a parameter so it can be used in SOQL query to count the associated contacts of that account record. How do I pass the parameter to SOQL query in the where clause? I tried the below but it didn't work.
Please use the below query it will resolve your issue:-
List<Contact> conList = [SELECT Id FROM Contact WHERE accountId =: recid];
Also in your query, the returned type is the list of accounts and you are assigning it to the list of Contact and also I have written a simple query instead of an inner query for the same purpose which you want to achieve. Let me know if you need any help on this.
Hope this explanation will resolve your query. Mark it as the best answer if you find it helpful. Thanks Akshay
Please use the below query it will resolve your issue:-
List<Contact> conList = [SELECT Id FROM Contact WHERE accountId =: recid];
Also in your query, the returned type is the list of accounts and you are assigning it to the list of Contact and also I have written a simple query instead of an inner query for the same purpose which you want to achieve. Let me know if you need any help on this.
Hope this explanation will resolve your query. Mark it as the best answer if you find it helpful. Thanks Akshay
Please use the below query it will resolve your issue:-
List<Contact> conList = [SELECT Id FROM Contact WHERE accountId =: recid];
Also in your query, the returned type is the list of accounts and you are assigning it to the list of Contact and also I have written a simple query instead of an inner query for the same purpose which you want to achieve. Let me know if you need any help on this.
Hope this explanation will resolve your query. Mark it as the best answer if you find it helpful.
Thanks
Akshay
All Answers
Greetings!
Seems like the parameter which is you are trying to pass to the method is recId but the variable you have used in the SOQL query is rec.
I would suggest you to try by using recId to see,if it fix the issue.
Kindly mark it as best answer if it helps so that it can help others in the future.
Warm Regards,
Shirisha Pathuri
Please use the below query it will resolve your issue:-
List<Contact> conList = [SELECT Id FROM Contact WHERE accountId =: recid];
Also in your query, the returned type is the list of accounts and you are assigning it to the list of Contact and also I have written a simple query instead of an inner query for the same purpose which you want to achieve. Let me know if you need any help on this.
Hope this explanation will resolve your query. Mark it as the best answer if you find it helpful.
Thanks
Akshay
Replace WHERE Id = '+rec' with WHERE AccountId = recId.
Regards,
Hemanth MSNS