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

Find all cases assigned to an account

Is there anyway to do this?  The current way I am doing this is by Querying the contacts table for all the contactID's linked to an account.  Then I have to Query the cases table for all the cases that are link to the list of contactIDs.  Is there any easier way to simple get all the cases that are link to an account?
In our next release, we are planning to make accountid an available field on case.

In the short term, I heard a customer was able to create a formula field on case that is the accountid, and was able to query that in soql.  I don't think we intended to expose this, and I've never tried it, but it might work for you.  Then it's easy to filter on that accountid field on the case.

This is what i did to pull all cases from x account;

Account ac = new Account();

string somefield = "123456789";

qrCases = sfs.query("Select id from Account where Account.x = '" + somefield + "'");

Account account = ((Account)qrCases.records[0]);

qrCases = sfs.query("Select Id from Contact where AccountId = '" + account.Id + "'");

Contact contact = ((Contact)qrCases.records[0]);

qrCases = sfs.query("Select id,CaseNumber,Subject,CreatedDate,Status from Case where ContactId = '" + contact.Id + "'");

sObject[] records = qrCases.records;

DataSet ds = new DataSet();

DataTable dt = ds.Tables.Add();





for (int i = 0; i < records.Length; i++)


Case cases = (Case)records[i];

ds.Tables[0].Rows.Add(cases.Id, cases.CaseNumber, cases.Subject, cases.Status);


this.GridView1.DataSource = ds;


The formula field sound quite interesting please let me know how to acomplish this.