You need to sign in to do that
Don't have an account?
sumit d
test class for contentDocumentLink trigger helper
Hi All,
My Helper class is given below:-
/*
* Trigger Helper Class to parse image response
* Parse Image response From social post
* */
public without sharing class ContentDocumentLinkTriggerHelper {
public static List<ContentDocumentLink> newList;
public static List<ContentDocumentLink> oldList;
public static Map<Id, ContentDocumentLink> newMap;
public static Map<Id, ContentDocumentLink> oldMap;
public static Boolean runTrigger = true;
// method to Parse Image response from social Post
public static void parseImageResponse(){
Set<Id> socialPostIds = new Set<Id>(newMap.keySet());
List<Predictions__c> pdcList = new List<Predictions__c>();
Set<Id> setLinkId = new Set<Id>();
for(contentdocumentlink cdl : newList){
if(String.valueOf((cdl.LinkedEntityId)).startsWith('0ST') && !setLinkId.contains(cdl.LinkedEntityId)){
String jsonResponse = EinsteenPredictionService.getImagePrediction('test');
EinsteenPredictionService ep= EinsteenPredictionService.parseImagePrediction(jsonResponse);
for(EinsteenPredictionService.cls_probabilities result: ep.probabilities) {
Predictions__c pc = new Predictions__c();
pc.Label__c = result.label;
pc.Probability__c = result.probability;
pc.Social_Post__c = cdl.LinkedEntityId;
pdcList.add(pc);
}
setLinkId.add(cdl.LinkedEntityId);
}
}
//Check Prediction list Has value or not
if(pdcList.size() > 0){
insert pdcList;
}
}
}
how to write test class for this helper class?
Any suggestions?
My Helper class is given below:-
/*
* Trigger Helper Class to parse image response
* Parse Image response From social post
* */
public without sharing class ContentDocumentLinkTriggerHelper {
public static List<ContentDocumentLink> newList;
public static List<ContentDocumentLink> oldList;
public static Map<Id, ContentDocumentLink> newMap;
public static Map<Id, ContentDocumentLink> oldMap;
public static Boolean runTrigger = true;
// method to Parse Image response from social Post
public static void parseImageResponse(){
Set<Id> socialPostIds = new Set<Id>(newMap.keySet());
List<Predictions__c> pdcList = new List<Predictions__c>();
Set<Id> setLinkId = new Set<Id>();
for(contentdocumentlink cdl : newList){
if(String.valueOf((cdl.LinkedEntityId)).startsWith('0ST') && !setLinkId.contains(cdl.LinkedEntityId)){
String jsonResponse = EinsteenPredictionService.getImagePrediction('test');
EinsteenPredictionService ep= EinsteenPredictionService.parseImagePrediction(jsonResponse);
for(EinsteenPredictionService.cls_probabilities result: ep.probabilities) {
Predictions__c pc = new Predictions__c();
pc.Label__c = result.label;
pc.Probability__c = result.probability;
pc.Social_Post__c = cdl.LinkedEntityId;
pdcList.add(pc);
}
setLinkId.add(cdl.LinkedEntityId);
}
}
//Check Prediction list Has value or not
if(pdcList.size() > 0){
insert pdcList;
}
}
}
how to write test class for this helper class?
Any suggestions?
https://gist.github.com/xgeek-net/b96fa1794899f4c31428
Hi Sumit,
You can start with below code and customize as per your logic:
Let me know if it helps. If it does, kindly mark this question as Best.
Thanks,
Kamal
its giving this error:-System.UnexpectedException: ContentPublication Limit exceeded.