You need to sign in to do that
Don't have an account?
SIVA KUMAR 507
Hey all I need Apex test class for the below code please help me guys.
Apex Class:
______________
public class AskEDD_ArticleAction {
@InvocableMethod
public static List<FlowOutputs> updateArticleTypeForDataCategories(List<FlowInputs> articleType)
{
List<Knowledge__kav> lstArticleType = [SELECT Id, Title, AskEDD_Category__c FROM Knowledge__kav WHERE Id =:articleType[0].recordId AND (PublishStatus = 'draft' OR Approval_Status__c = 'Pending Approval')];
List<Knowledge__DataCategorySelection> lstDC = [SELECT ParentId, DataCategoryName FROM Knowledge__DataCategorySelection
WHERE ParentId =:articleType[0].recordId];
List<FlowOutputs> outputlist = new List<FlowOutputs>();
FlowOutputs output = new FlowOutputs();
Map<Id, String> datacategoryNameMap = new Map<Id, String>();
for(Knowledge__DataCategorySelection dcObj:lstDC)
{
if(datacategoryNameMap.containsKey(dcObj.ParentId))
{
String str = datacategoryNameMap.get(dcObj.ParentId);
datacategoryNameMap.put(dcObj.ParentId, str + ',' + dcObj.DataCategoryName);
}
else
{
datacategoryNameMap.put(dcObj.ParentId, dcObj.DataCategoryName);
}
}
for(Knowledge__kav artObj:lstArticleType)
{
if(datacategoryNameMap.containsKey(artObj.Id))
{
artObj.AskEDD_Category__c = datacategoryNameMap.get(artObj.Id);
if (String.isEmpty(artObj.AskEDD_Category__c)){
output.noCategory = true;
outputlist.add(output);
return outputlist;
}
else {
output.noCategory = false;
outputlist.add(output);
}
// output.categoryString = artObj.AskEDD_Category__c;
}
}
// update lstArticleType;
return outputlist;
}
public class FlowInputs {
@InvocableVariable
public string recordId;
}
public class FlowOutputs {
@InvocableVariable
public boolean noCategory;
}
}
______________
public class AskEDD_ArticleAction {
@InvocableMethod
public static List<FlowOutputs> updateArticleTypeForDataCategories(List<FlowInputs> articleType)
{
List<Knowledge__kav> lstArticleType = [SELECT Id, Title, AskEDD_Category__c FROM Knowledge__kav WHERE Id =:articleType[0].recordId AND (PublishStatus = 'draft' OR Approval_Status__c = 'Pending Approval')];
List<Knowledge__DataCategorySelection> lstDC = [SELECT ParentId, DataCategoryName FROM Knowledge__DataCategorySelection
WHERE ParentId =:articleType[0].recordId];
List<FlowOutputs> outputlist = new List<FlowOutputs>();
FlowOutputs output = new FlowOutputs();
Map<Id, String> datacategoryNameMap = new Map<Id, String>();
for(Knowledge__DataCategorySelection dcObj:lstDC)
{
if(datacategoryNameMap.containsKey(dcObj.ParentId))
{
String str = datacategoryNameMap.get(dcObj.ParentId);
datacategoryNameMap.put(dcObj.ParentId, str + ',' + dcObj.DataCategoryName);
}
else
{
datacategoryNameMap.put(dcObj.ParentId, dcObj.DataCategoryName);
}
}
for(Knowledge__kav artObj:lstArticleType)
{
if(datacategoryNameMap.containsKey(artObj.Id))
{
artObj.AskEDD_Category__c = datacategoryNameMap.get(artObj.Id);
if (String.isEmpty(artObj.AskEDD_Category__c)){
output.noCategory = true;
outputlist.add(output);
return outputlist;
}
else {
output.noCategory = false;
outputlist.add(output);
}
// output.categoryString = artObj.AskEDD_Category__c;
}
}
// update lstArticleType;
return outputlist;
}
public class FlowInputs {
@InvocableVariable
public string recordId;
}
public class FlowOutputs {
@InvocableVariable
public boolean noCategory;
}
}
You can try this test class:-
All Answers
I Need test class for that class please help me
You can take reference from this below code.
In case you find any other issue please mention.
If you find your Solution then mark this as the best answer.
Thanks and Regards
Suraj Tripathi.
When i run the test class in my org I covered 87%
Please check your test class and tell me whai is the error comes in your code.
Thanks
i am getting below errors can you please solve it.
.
you are getting this error because you have not created the Data Category Groups in your org.
You can follow these steps:-
--> Click on Gear Icon and Select Service Setup.
--> Enter Data Category Setup in the Quick Find box and select Data Category Setup.
--> In Category groups click new and fill the group name as KnowledgeArticleVersion and save it.
--> Activate Category group.
--> In Categories in KnowledgeArticleVersion section.
--> Click the action tab and then click Add child category and fill the name as student then click on Add and then again fill name as Geography and click on save button.
Please mark it as the best answer if it helps.
Thanks.
Check this test class:-
You can try this test class:-
__________________________________________
global class AskEDD_ArticleDataCategories implements Schedulable {
global void execute(SchedulableContext ctx) {
List<Knowledge__DataCategorySelection> dataCategories = [SELECT Id, DataCategoryGroupName, DataCategoryName, ParentId
FROM Knowledge__DataCategorySelection
WHERE SystemModstamp >= LAST_N_DAYS:1];
if(dataCategories.Size() > 0) {
List<String> parentIds = new List<String>();
for(Knowledge__DataCategorySelection dataCategory : dataCategories) {
parentIds.add(dataCategory.ParentId);
}
dataCategories = [SELECT Id, DataCategoryGroupName, DataCategoryName, ParentId
FROM Knowledge__DataCategorySelection
WHERE ParentId IN: parentIds];
Map<String, String> parentIdMap = new Map<String, String>();
for(Knowledge__DataCategorySelection dataCategory : dataCategories) {
if(parentIdMap.get(dataCategory.ParentId) == null) {
parentIdMap.put(dataCategory.ParentId, dataCategory.DataCategoryName);
}
else {
String temp = parentIdMap.get(dataCategory.ParentId) + ';' + dataCategory.DataCategoryName;
parentIdMap.put(dataCategory.ParentId, temp);
}
}
List<Knowledge__kav> articles = [SELECT Id, AskEDD_Category__c FROM Knowledge__kav WHERE Id IN: parentIdMap.keySet() AND PublishStatus = 'Draft'];
for(Knowledge__kav article : articles) {
article.AskEDD_Category__c = parentIdMap.get(article.Id);
}
update articles;
}
}
}
You can try this test class:-