You need to sign in to do that
Don't have an account?
Mukesh Kumar 470
please help me how to write test class for below code.
public without sharing class FileUpload_ctrl {
@AuraEnabled
public static Id saveFile(Id parentId, String fileName, String base64Data, String contentType, String fileDescription ) {
ContentVersion contentToInsert = new ContentVersion();
contentToInsert.Title = fileDescription + ' - ' + fileName;
contentToInsert.VersionData = EncodingUtil.base64Decode(EncodingUtil.urlDecode(base64Data, 'UTF-8'));
contentToInsert.PathOnClient = '/' + fileName ;
contentToInsert.Description = fileDescription;
contentToInsert.IsMajorVersion = false;
insert contentToInsert;
contentToInsert = [select id, ContentDocumentId from ContentVersion WHERE Id =: contentToInsert.Id];
ContentDocumentLink cl = new ContentDocumentLink();
cl.ContentDocumentId = contentToInsert.ContentDocumentId;
cl.LinkedEntityId = parentId;
cl.ShareType = 'V';
cl.Visibility = 'AllUsers';
insert cl;
return contentToInsert.id;
}
}
@AuraEnabled
public static Id saveFile(Id parentId, String fileName, String base64Data, String contentType, String fileDescription ) {
ContentVersion contentToInsert = new ContentVersion();
contentToInsert.Title = fileDescription + ' - ' + fileName;
contentToInsert.VersionData = EncodingUtil.base64Decode(EncodingUtil.urlDecode(base64Data, 'UTF-8'));
contentToInsert.PathOnClient = '/' + fileName ;
contentToInsert.Description = fileDescription;
contentToInsert.IsMajorVersion = false;
insert contentToInsert;
contentToInsert = [select id, ContentDocumentId from ContentVersion WHERE Id =: contentToInsert.Id];
ContentDocumentLink cl = new ContentDocumentLink();
cl.ContentDocumentId = contentToInsert.ContentDocumentId;
cl.LinkedEntityId = parentId;
cl.ShareType = 'V';
cl.Visibility = 'AllUsers';
insert cl;
return contentToInsert.id;
}
}
Try Below Code Please Mark It As Best Answer If It Helps
Thank You!
All Answers
Try Below test Class Please Mark It As Best Answer If It Helps
Thank You!
https://salesforce.stackexchange.com/questions/244788/how-do-i-write-an-apex-unit-test
https://salesforce.stackexchange.com/questions/244794/how-do-i-increase-my-code-coverage-or-why-cant-i-cover-these-lines
Thanks!
Try Below Code Please Mark It As Best Answer If It Helps
Thank You!