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
sf.dev.ax1103sf.dev.ax1103 

soql help plz

Hi All,

        

    I need to get the count of closedcases with an attachments. so for this I tried using following query but no hope.

 

        Select a.Id,a.ParentId From Attachment a where a.ParentId like '500%' 

 

Any help plz

SuperfellSuperfell

select id, parentId from attachment where parent.type='case'

sf.dev.ax1103sf.dev.ax1103

Thanks Simon,

 

              How to get attachments with Closed Cases only ?

sf.dev.ax1103sf.dev.ax1103

Simon,

              I tried below query but i am getting an error.

 

              Select a.Id,a.parentId  From Attachment a where a.parent.type ='case'  and a.parent.status = 'closed'

Damien_Damien_

It would be helpful to know what your error is

Also since you don't know what the parent is, you can't refer to the Parent.Status since it might not be a Case

I believe this is what causes your error.

 

Alternatively:

//Yes this method isn't as good, but it's easier.

SELECT (SELECT Id FROM Attachments) FROM Case WHERE Status = 'Closed'

Loop through all and increment a number when the Case.Attachments.size() > 0

 

sf.dev.ax1103sf.dev.ax1103

Error Message that i get is  " Invalid field . NO Such Column Status on entity Name "

Damien_Damien_

Ok, so that means I was right in my guess.  Try my alternative, it will work.

sf.dev.ax1103sf.dev.ax1103

But i need get the count of closed cases with attachments in a data loader.I need to email count to my boss.

Rahul SharmaRahul Sharma

Would like to elaborate Damein's idea,

run this in system log:

Integer countAttachments = 0;
for(Case objCase : [SELECT (SELECT Id FROM Attachments) FROM Case WHERE Status = 'Closed'])
{
	if(!objCase.Attachments.isEmpty())
	{
		for(Attactment objA : objCase.Attachments)
		{
			countAttachments += countAttachments;
		}
	}
}
system.debug('====Desired count====='+countAttachments);

 

sf.dev.ax1103sf.dev.ax1103

Thanks Rahul.

 

             I am getting an error .System.LimitException: Too many query rows: 50001.Can you please tell me how to fix this error.



Damien_Damien_

You can only query 50k records at once.  I had thought there was some workaround to that but I cannot find it right now for some reason.

 

I believe he wanted the count of Cases that have attachments.  In that case it would be more like:

 

system.debug('====Desired count====='+countAttachments);

integer casesAttached = 0;
for(Case objCase : [SELECT (SELECT Id FROM Attachments) FROM Case WHERE Status = 'Closed'])
{
	if(!objCase.Attachments.isEmpty())
	{
		++casesAttached ;
	}
} 
system.debug('====Desired count====='+ casesAttached);
Rahul SharmaRahul Sharma

As the data is more than 50k records, shift the logic to a batch apex.

sf.dev.ax1103sf.dev.ax1103

Thanks Rahul. Can you help in putting above logic in batch apex.Is it possible to execute batch apex from system log?.I just need the count of cases with attachments.I just need to give the count to my boss.