You need to sign in to do that
Don't have an account?
AntonPavlov
Help to write Test class apex
This is code apex
public class displayImageController {
@AuraEnabled
public static List<String> getImage(Id CurrentId){
List<String> files =new List<String>();
List<ContentDocumentLink> cdLinks =[SELECT Id,ContentDocument.LatestPublishedVersionID,ContentDocumentId FROM ContentDocumentLink WHERE LinkedEntityId=:CurrentId];
for(ContentDocumentLink cdl: cdLinks){
String FileExtension =[SELECT FileExtension FROM ContentVersion WHERE ContentDocumentId=:cdl.ContentDocumentId].get(0).FileExtension;
if(Pattern.matches('(png|jpg|jpeg|gif|svg)', FileExtension)){
files.add(URL.getSalesforceBaseUrl().toExternalForm() +'/sfc/servlet.shepherd/version/download/'+cdl.ContentDocument.LatestPublishedVersionID);
}
}
return files;
}
}
Apex test I don't know what write next
@isTest
public class displayImageControllerTest {
private static testMethod void testCreate() {
Account testAccount = new Account();
testAccount.Name='Test Account' ;
insert testAccount;
Contact cont = new Contact ();
cont.FirstName = 'FirstName';
cont.LastName = 'LastName';
cont.Email='email233@email.com';
cont.phone='12345678';
insert cont;
Account acct = new Account(Name='TEST');
insert acct;
ContentVersion contentVersion = new ContentVersion(
Title = 'Penguins',
PathOnClient = 'Penguins.jpg',
VersionData = Blob.valueOf('Test Content'),
IsMajorVersion = true
);
insert contentVersion;
List<ContentDocument> documents = [SELECT Id, Title, LatestPublishedVersionId FROM ContentDocument];
ContentDocumentLink cdl = New ContentDocumentLink();
cdl.LinkedEntityId = acct.id;
cdl.ContentDocumentId = documents[0].Id;
cdl.shareType = 'V';
insert cdl;
}
}
public class displayImageController {
@AuraEnabled
public static List<String> getImage(Id CurrentId){
List<String> files =new List<String>();
List<ContentDocumentLink> cdLinks =[SELECT Id,ContentDocument.LatestPublishedVersionID,ContentDocumentId FROM ContentDocumentLink WHERE LinkedEntityId=:CurrentId];
for(ContentDocumentLink cdl: cdLinks){
String FileExtension =[SELECT FileExtension FROM ContentVersion WHERE ContentDocumentId=:cdl.ContentDocumentId].get(0).FileExtension;
if(Pattern.matches('(png|jpg|jpeg|gif|svg)', FileExtension)){
files.add(URL.getSalesforceBaseUrl().toExternalForm() +'/sfc/servlet.shepherd/version/download/'+cdl.ContentDocument.LatestPublishedVersionID);
}
}
return files;
}
}
Apex test I don't know what write next
@isTest
public class displayImageControllerTest {
private static testMethod void testCreate() {
Account testAccount = new Account();
testAccount.Name='Test Account' ;
insert testAccount;
Contact cont = new Contact ();
cont.FirstName = 'FirstName';
cont.LastName = 'LastName';
cont.Email='email233@email.com';
cont.phone='12345678';
insert cont;
Account acct = new Account(Name='TEST');
insert acct;
ContentVersion contentVersion = new ContentVersion(
Title = 'Penguins',
PathOnClient = 'Penguins.jpg',
VersionData = Blob.valueOf('Test Content'),
IsMajorVersion = true
);
insert contentVersion;
List<ContentDocument> documents = [SELECT Id, Title, LatestPublishedVersionId FROM ContentDocument];
ContentDocumentLink cdl = New ContentDocumentLink();
cdl.LinkedEntityId = acct.id;
cdl.ContentDocumentId = documents[0].Id;
cdl.shareType = 'V';
insert cdl;
}
}
Just you have to call the method and need to pass the account id.
Please use the below updated one:
Thanks,
Maharajan.C
All Answers
Just you have to call the method and need to pass the account id.
Please use the below updated one:
Thanks,
Maharajan.C