You need to sign in to do that
Don't have an account?
Jack Rose 1
Unable to deploy without Apex Test
Hi,
Really hoping someone is able to help me with an issue I'm having. I am a Salesforce Admin with no developer to hand.
I am trying to do a change set to our Production Org, for a Apex Class. The purpose of the class is to insert the Data Categories into Custom Fields on the Knowledge Article.
Unfortunately my change set failed as my test coverage was 0%.
I have since discovered that I need a test class for the Apex Class but have no idea where to start.
Here is the class I have, any help would be greatly appreciated.
Really hoping someone is able to help me with an issue I'm having. I am a Salesforce Admin with no developer to hand.
I am trying to do a change set to our Production Org, for a Apex Class. The purpose of the class is to insert the Data Categories into Custom Fields on the Knowledge Article.
Unfortunately my change set failed as my test coverage was 0%.
I have since discovered that I need a test class for the Apex Class but have no idea where to start.
Here is the class I have, any help would be greatly appreciated.
public class DataCategoryMgmtDL4B { @InvocableMethod public static void updateArticleTypeForDataCategories(List<Id> articleTypeIds) { List<string> DL4B_Products = new List<String>{'Property_Owner_Residential','Property_Owner_Commercial','Tradesman','Retail','Business_From_Home','Office_and_Surgery','Hotel','Pub_Restaurant','Tradesman_Professional','Property_Owner','Bed_Breakfast','Hair_Beauty','Office_Professional','Professional_Indemnity','Cyber','Van'}; List<string> DL4B_Systems = new List<String>{'Acturis_ETrade','Evo','IS2000','PI_Legacy','SSP','UIS'}; List<Knowledge__kav> lstArticleType = [SELECT Id, Title, DL4B_Data_Categories__c, DL4B_Systems_Categories__c FROM Knowledge__kav WHERE Id IN:articleTypeIds AND PublishStatus = 'draft']; List<Knowledge__DataCategorySelection> lstDC = [SELECT ParentId, DataCategoryName FROM Knowledge__DataCategorySelection WHERE ParentId IN:articleTypeIds]; 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)) { system.debug(datacategoryNameMap.get(artObj.Id)); String allDataCategories = datacategoryNameMap.get(artObj.Id); List<String> parts = datacategoryNameMap.get(artObj.Id).split(';'); artObj.DL4B_Data_Categories__c = ''; artObj.DL4B_Systems_Categories__c = ''; for(String unix: parts) { if(DL4B_Products.contains(unix)){ artObj.DL4B_Data_Categories__c += unix + ';'; } if(DL4B_Systems.contains(unix)){ artObj.DL4B_Systems_Categories__c += unix + ';'; } } } update lstArticleType; } }}
Raj Vakati
Try this test class