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
NewBee21NewBee21 

Getting error while trying to fetch list of open cases related to Account -SOQL Query

public class CaseAccount {
public static void (){
Account accts=[SELECT Id, name FROM Account WHERE Id NOT IN ( SELECT AccountId FROM Case WHERE IsClosed = true ) ] ; } }

Error I am getting :
1.static is not allowed on constructors
2.Invalid constructor name: method

What could be the reason and how do I navigate to solution. Previously I used static in other example and at that time I did not get any erros.

requirement: "Write a class to get the list of all open cases related to an account. Class should have one method with account id as an input parameter and return list of cases
Best Answer chosen by NewBee21
CharuDuttCharuDutt
Hii New Bee
Try Below Class
public Class AccountRelatedCase{
	public Static list<Case> lstCases(string Accid){
	
	list<Case> lstCa = [SELECT AccountId,CaseNumber,Subject FROM Case WHERE status = 'New' And AccountId = :Accid];
	system.Debug(lstCa);
	return lstCa;
	}
}
Please Mark It As Best Answer If It Helps
Thank You!

All Answers

CharuDuttCharuDutt
Hii New Bee
Try Below Class
public Class AccountRelatedCase{
	public Static list<Case> lstCases(string Accid){
	
	list<Case> lstCa = [SELECT AccountId,CaseNumber,Subject FROM Case WHERE status = 'New' And AccountId = :Accid];
	system.Debug(lstCa);
	return lstCa;
	}
}
Please Mark It As Best Answer If It Helps
Thank You!
This was selected as the best answer
NewBee21NewBee21
Hey Charu,thanks a lot! I think this is the best answer.
But while executing it in anonymous window I am getting following error.

Line: 1, Column: 20
Method does not exist or incorrect signature: void lstCases() from the type AccountRelatedCase
CharuDuttCharuDutt
Hii NewBee
Copy Paste the Whole Code Save It Refresh The Window And Call it From Apex Anonymous Window Like This
'0012w00000G6nnWAAR' : This Has To Be The Account Id From Your Org

AccountRelatedCase.lstCases('0012w00000G6nnWAAR');
Please Mark It As Best Answer If It Helps
Thank You!
NewBee21NewBee21
Done Charu! it worked. I appreciate it a lot,Its the second time you helped me out :)
I have chosen it as THE Best Answer!

Also,could you please kindly suggest me some source so that I understand the SOQL better.I tried Apex basic and database trailhead module but it didn't work for me.