You need to sign in to do that
Don't have an account?
SIVA KUMAR 507
Hey All I need Test Class for the below code please help me guys.
Apex 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;
}
}
}
______________
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;
}
}
}
Hi Siva,
I have to continue your test class for this I need to know who is the parent of this "Knowledge__DataCategorySelection"
Name the Object which is the parent of "Knowledge__DataCategorySelection"?
"Knowledge__DataCategorySelection" with this name in my org there is no object suraj.
How Can I check That? Can You Please tell me?
Actually, this is not a standard object so I also don't know about it
let me research on it.
I will get back to you
Try this below test class and please share a Screenshot of the Test Coverage
when i save this code i am getting below errors.
for FlowDefination I thought it was object in your org and if all the field is not writable then how ould i write test class
No idea about it.
Please replace the below code and share screenshot
ok good
this eroor is showing from another class
go to flowcontroller_test class and comment all the code
Insert failed because of Parent Id
Now I need to know the Parent of this object "Knowledge__DataCategorySelection"
test class:
________
@isTest
Public Class AskEDD_ArticleDataCategoriesTest{
public static testMethod void testschedule() {
Knowledge__kav newFAQ = new Knowledge__kav();
newFAQ.Title = 'test1';
newFAQ.UrlName = 'test1';
insert newFAQ;
Knowledge__DataCategorySelection obj=new Knowledge__DataCategorySelection();
obj.DataCategoryGroupName='Test';
obj.DataCategoryName='Data';
obj.ParentId=newFaQ.id;
insert obj;
Test.StartTest();
AskEDD_ArticleDataCategories sh1 = new AskEDD_ArticleDataCategories ();
String sch = '0 0 23 * * ?'; system.schedule('Test Territory Check', sch, sh1);
Test.stopTest(); }
}