Discussions
- General Development
- Schema Development
- Apex Code Development
- Visualforce Development
- Formulas & Validation Rules
- Security
- Mobile
- Force.com Sites & Site.com
- Chatter Development
- Java Development
- .NET Development
- Perl, PHP, Python & Ruby
- Desktop Integration
- APIs and Integrations
- Visual Workflow
- Apple, Mac and OS X
- VB and Office Development
- AppExchange Directory & Packaging
- Salesforce Labs & Open Source Projects
- Other Salesforce Applications
- Jobs Board
- Force.com Discussion Boards
- :
- Developer Boards for Force.com and Database.com
- :
- Apex Code Development
- :
- How to "Bulkify" this method?
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
How to "Bulkify" this method?
[ Edited ]- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
01-02-2013 04:05 PM - edited 01-03-2013 08:51 AM
I am currently hitting the limit for 100 SOQL queries. I have a method that takes a case ID and returns a boolean to indicate if the case has a public article attached or not. The problem is that I cannot see the way to have this method work in bulk, that meaning, taking a list or a set of case ids and returning a map of caseis and booleans.
This is the code currently working for a single case (or for a small number of cases). I want to be able to call the getPubliArticles method like this:
map<Id, Boolean> caseArticlesmap = getPublicArticles(caseids); //so that then I can iterate over this map.
These are the methods tha I am currently using.
private List<KnowledgeArticleVersion> loadArticlesAttachedToCase(){
List<KnowledgeArticleVersion> attachedArticles = new List<KnowledgeArticleVersion>();
List<CaseArticle> caseAssociations = [
select KnowledgeArticleId, ArticleLanguage
from CaseArticle
where CaseId =:CaseId];
if (caseAssociations != null && caseAssociations.size() > 0){
for (CaseArticle association : caseAssociations){
String strKnowledgeArticleId = association.KnowledgeArticleId;
String strArticleLanguage = association.ArticleLanguage;
String aQry = 'select id, Title, KnowledgeArticleId, Language, UrlName '
+ 'from KnowledgeArticleVersion '
+ 'where KnowledgeArticleId = :strKnowledgeArticleId '
+ 'and PublishStatus = \'Online\' '
+ 'and Language = :strArticleLanguage '
+ 'and IsVisibleInPKB = true '
+ 'order by KnowledgeArticleId';
List<KnowledgeArticleVersion> kav = Database.query(aQry);
if (kav.size() > 0) {
attachedArticles.add(kav[0]);
}
}
}
return attachedArticles;
}
Thanks in advance! Any help will be greatly appreciated.
Re: How to "Bulkify" this method?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
01-02-2013 10:19 PM
Hi
Salesforce best practices : don't write soql queries inside for loop but you had written soql query inside for loop.
http://wiki.developerforce.com/page/Apex_Code_Best
Re: How to "Bulkify" this method?
[ Edited ]- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
01-03-2013 01:14 AM - edited 01-03-2013 08:52 AM
I was able to get this working.

