You need to sign in to do that
Don't have an account?
Pallavi singh
Test Class for the apex class
Hello,
Need help to write a test class for the apex class.
Thank you in advance
public without sharing class Fileuploadcttrl {
@AuraEnabled(cacheable=true)
public static List<ContentVersion> fetchPassportFiles(String recordId){
List<ContentVersion> documents =new List<ContentVersion>();
DateTime nowDT=System.now();
String formatted=nowDT.format('dd_MM_yyyy');
// set<id> contentdocIds=new set<id>();
for(ContentVersion cv : [SELECT Id,ContentDocumentId, Title, CreatedDate, FileType, ContentSize From ContentVersion WHERE FirstPublishLocationId =: recordId]){
if( cv.Title.contains('Diplomatic Passport') && cv.Title!='')
{
cv.Title = cv.title + ' ' + nowDT;
documents.add(cv);
}
// contentdocIds.add(cv.ContentDocumentId);
}
// updateDocumentTitle(contentdocIds);
return documents;
}
//@future
public static void updateDocumentTitle(set<id> contentdocIds){
DateTime nowDT=System.now();
String formatted=nowDT.format('dd_MM_yyyy');
list<ContentDocument> contDocList=new list<ContentDocument>();
for (ContentDocument doc:[select id, Title from ContentDocument where id=:contentdocIds]){
if(doc.Title!=''&& doc.Title!='null'){
doc.Title = doc.title + ' ' + nowDT;
contDocList.add(doc);
}
}
update contDocList;
}
@AuraEnabled(cacheable=true)
public static List<ContentVersion> fetchStatusFiles(String recordId){
List<ContentVersion> documents =new List<ContentVersion>();
DateTime nowDT=System.now();
String formatted=nowDT.format('dd_MM_yyyy');
for(ContentVersion cvs : [SELECT Id, Title, CreatedDate, FileType, ContentSize From ContentVersion WHERE FirstPublishLocationId =: recordId]){
if( cvs.Title.contains('Status Certificate') && cvs.Title!='')
{
cvs.Title = cvs.title + ' ' + nowDT;
documents.add(cvs);
}
}
return documents;
}
}
Need help to write a test class for the apex class.
Thank you in advance
public without sharing class Fileuploadcttrl {
@AuraEnabled(cacheable=true)
public static List<ContentVersion> fetchPassportFiles(String recordId){
List<ContentVersion> documents =new List<ContentVersion>();
DateTime nowDT=System.now();
String formatted=nowDT.format('dd_MM_yyyy');
// set<id> contentdocIds=new set<id>();
for(ContentVersion cv : [SELECT Id,ContentDocumentId, Title, CreatedDate, FileType, ContentSize From ContentVersion WHERE FirstPublishLocationId =: recordId]){
if( cv.Title.contains('Diplomatic Passport') && cv.Title!='')
{
cv.Title = cv.title + ' ' + nowDT;
documents.add(cv);
}
// contentdocIds.add(cv.ContentDocumentId);
}
// updateDocumentTitle(contentdocIds);
return documents;
}
//@future
public static void updateDocumentTitle(set<id> contentdocIds){
DateTime nowDT=System.now();
String formatted=nowDT.format('dd_MM_yyyy');
list<ContentDocument> contDocList=new list<ContentDocument>();
for (ContentDocument doc:[select id, Title from ContentDocument where id=:contentdocIds]){
if(doc.Title!=''&& doc.Title!='null'){
doc.Title = doc.title + ' ' + nowDT;
contDocList.add(doc);
}
}
update contDocList;
}
@AuraEnabled(cacheable=true)
public static List<ContentVersion> fetchStatusFiles(String recordId){
List<ContentVersion> documents =new List<ContentVersion>();
DateTime nowDT=System.now();
String formatted=nowDT.format('dd_MM_yyyy');
for(ContentVersion cvs : [SELECT Id, Title, CreatedDate, FileType, ContentSize From ContentVersion WHERE FirstPublishLocationId =: recordId]){
if( cvs.Title.contains('Status Certificate') && cvs.Title!='')
{
cvs.Title = cvs.title + ' ' + nowDT;
documents.add(cvs);
}
}
return documents;
}
}
Can you try the below test class,it gives you 100% coverage .
Let me know if you face any issues.
If this solution helps, Please mark it as best answer.
Thanks,
All Answers
I dont see you are calling updateDocumentTitle future method anywhere from this class. It is called explictly from lightning page?
Thanks,
Yes this is the correct apex class.
public without sharing class Fileuploadcttrl {
@AuraEnabled(cacheable=true)
public static List<ContentVersion> fetchPassportFiles(String recordId){
List<ContentVersion> documents =new List<ContentVersion>();
DateTime nowDT=System.now();
String formatted=nowDT.format('dd_MM_yyyy');
// set<id> contentdocIds=new set<id>();
for(ContentVersion cv : [SELECT Id,ContentDocumentId, Title, CreatedDate, FileType, ContentSize From ContentVersion WHERE FirstPublishLocationId =: recordId]){
if( cv.Title.contains('Diplomatic Passport') && cv.Title!='')
{
cv.Title = cv.title + ' ' + nowDT;
documents.add(cv);
}
// contentdocIds.add(cv.ContentDocumentId);
}
// updateDocumentTitle(contentdocIds);
return documents;
}
@AuraEnabled(cacheable=true)
public static List<ContentVersion> fetchStatusFiles(String recordId){
List<ContentVersion> documents =new List<ContentVersion>();
DateTime nowDT=System.now();
String formatted=nowDT.format('dd_MM_yyyy');
for(ContentVersion cvs : [SELECT Id, Title, CreatedDate, FileType, ContentSize From ContentVersion WHERE FirstPublishLocationId =: recordId]){
if( cvs.Title.contains('Status Certificate') && cvs.Title!='')
{
cvs.Title = cvs.title + ' ' + nowDT;
documents.add(cvs);
}
}
return documents;
}
}
Can you try the below test class,it gives you 100% coverage .
Let me know if you face any issues.
If this solution helps, Please mark it as best answer.
Thanks,