You need to sign in to do that
Don't have an account?
Priti jaiswal 8
Get attachment parent ownerid via soql
Hello All,
I am trying to get the attachment parent owner id via SOQL, but it did not return any data.
Currently i have written individual query for each object to get the ownerId.
The problem here is, if we are having more than 10 parent objects then we have to write individual SOQL for each object, which looks quote ugly.
Any suggestion or solution is much appreciated.
Thanks in advance!!
I am trying to get the attachment parent owner id via SOQL, but it did not return any data.
Currently i have written individual query for each object to get the ownerId.
The problem here is, if we are having more than 10 parent objects then we have to write individual SOQL for each object, which looks quote ugly.
Any suggestion or solution is much appreciated.
Thanks in advance!!
Hello Priti,
Try with the following code it may help you.
The only limitation is parent objects should not be greater than 100.
Any bugs we can overcome, need to spend time on the above code.
I hope this helps you if its please mark it solved.
Thanks
Arshad
Thanks for the response!!
The issue that i can see here is Database.Query(Query) is inside for loop. I our code we are stuck at this point only.
for(String sobjectName :parentIds_sObjectMap.keySet())
{
SET<ID> keys_Id = parentIds_sObjectMap.get(sobjectName);
String Query = 'Select id,OwnerId FROM '+sobjectName+' Where Id in :keys_Id ';
for(sObject sObj :Database.Query(Query))
parentId_To_OwnerId.put((ID)sObj.get('Id'),(Id)sObj.get('OwnerId'));
}
Regards,
Priti
I do understand that I've broken the best practice principle, but to overcome code breaking.
i have used entry condition probaly you can modify as per your requirement.
if(parentIds_sObjectMap != null && parentIds_sObjectMap.keyset().size()<100){
}
Since Soql call inside for loop will throw Exception on 101 soql call.
Need to dedicate more time for resolving the issue.
Thanks
Arshad
Did you figure out the issue, let us know the solution.
So that it can help the community.
Thanks.