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.
Apex Class:
____________
public class EDDKMSCreateArticleFromTemplate {
@AuraEnabled
public static List<Knowledge_Article_Template__c> getKnowledgeArticleTemplates() {
try {
return [SELECT Id, Name FROM Knowledge_Article_Template__c];
}
catch(Exception ex) {
throw new AuraHandledException(ex.getMessage());
}
}
@AuraEnabled
public static TemplateWrapper getKnowledgeArticleTemplateBody(String templateId, String templateName) {
try {
TemplateWrapper wrapper = new TemplateWrapper();
if(Schema.SObjectType.Knowledge__kav.getRecordTypeInfosByName().get(templateName) != null)
wrapper.recordTypeId = Schema.SObjectType.Knowledge__kav.getRecordTypeInfosByName().get(templateName).getRecordTypeId();
else
wrapper.recordTypeId = '';
wrapper.template = [SELECT Id, Name, Template_Body__c, OT_Body__c, CF_Body__c, DET_Body__c,
ADJ_Body__c, MGR_OT_EPR_Body__c, MGR_UISD_Body__c
FROM Knowledge_Article_Template__c
WHERE Id =: templateId];
return wrapper;
}
catch(Exception ex) {
throw new AuraHandledException(ex.getMessage());
}
}
public class TemplateWrapper {
@AuraEnabled public String recordTypeId {get;set;}
@AuraEnabled public Knowledge_Article_Template__c template {get;set;}
}
}
____________
public class EDDKMSCreateArticleFromTemplate {
@AuraEnabled
public static List<Knowledge_Article_Template__c> getKnowledgeArticleTemplates() {
try {
return [SELECT Id, Name FROM Knowledge_Article_Template__c];
}
catch(Exception ex) {
throw new AuraHandledException(ex.getMessage());
}
}
@AuraEnabled
public static TemplateWrapper getKnowledgeArticleTemplateBody(String templateId, String templateName) {
try {
TemplateWrapper wrapper = new TemplateWrapper();
if(Schema.SObjectType.Knowledge__kav.getRecordTypeInfosByName().get(templateName) != null)
wrapper.recordTypeId = Schema.SObjectType.Knowledge__kav.getRecordTypeInfosByName().get(templateName).getRecordTypeId();
else
wrapper.recordTypeId = '';
wrapper.template = [SELECT Id, Name, Template_Body__c, OT_Body__c, CF_Body__c, DET_Body__c,
ADJ_Body__c, MGR_OT_EPR_Body__c, MGR_UISD_Body__c
FROM Knowledge_Article_Template__c
WHERE Id =: templateId];
return wrapper;
}
catch(Exception ex) {
throw new AuraHandledException(ex.getMessage());
}
}
public class TemplateWrapper {
@AuraEnabled public String recordTypeId {get;set;}
@AuraEnabled public Knowledge_Article_Template__c template {get;set;}
}
}
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.
All Answers
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.
thanks for your reply. when I run the test class i covered only 55%. and i am getting below errors
When I run the test class in my org I covered 77%
Please check the error in your test class afterthat you tell me what is the error.
Thanks.
When i run the test class in my org I covered 55% and i am getting below errors.
This error is getting in your test class because you have not created the recordtype inside the Knowledge__kav Object.
Follow these steps:-
--> Go to the Setup --> click the object manager --> Search Knowledge__kav object --> click the Knowledge__kav object.
--> In the left side You will be seeing the recordType option --> Click the recordtype
If the recordType is already created in your org then copy the recordtype name and paste this name inside the test class
Id recId = Schema.SObjectType.Knowledge__kav.getRecordTypeInfosByName().get('FAQ').getRecordTypeId() you will paste the recordtype name in place of the 'FAQ' recordtype name.
And if the record type is not created in your org then you will create the recordtype and the name of the recordtype will paste instead of the 'FAQ' recordType name.
If you will doing these steps Maybe your class will run successfully.
Thanks Siva