@isTest public class TestController { @IsTest static void TestControllerMethod() { Contact con = new Contact(); con.LastName = 'LastName'; insert con; ContentVersion testContent = new ContentVersion(); testContent.Title = 'Profilejiou'; testContent.PathOnClient = 'version.jpg'; testContent.VersionData = Blob.valueOf('Profilejiou'); insert testContent; Id contentDocumentId = [SELECT ContentDocumentId FROM ContentVersion WHERE Id = :testContent.Id].ContentDocumentId; ContentDocumentLink cdl = new ContentDocumentLink(); cdl.ContentDocumentId = contentDocumentId; cdl.LinkedEntityId = con.Id; insert cdl; Listdc=[SELECT Id FROM ContentDocument WHERE Id=:contentDocumentId]; ContentDistribution link12 = new ContentDistribution(); link12.Name='hiiii'; link12.ContentVersionId =testContent.Id ; insert link12; // ContentDistribution cds = [SELECT DistributionPublicUrl FROM ContentDistribution WHERE Id=:link12.Id]; Listconlist=[SELECT Id,LastName,Image_url__c,Description FROM Contact WHERE Id =:con.Id]; List updatec = new List(); for (Contact contact : conlist) { contact.Description = 'attachment inserted ftw'; //contact.PublicUrlOfAttachment__c=cds.DistributionPublicUrl; if(testContent.Title.containsIgnoreCase('Profile')) { contact.Image_url__c='https://suprnova-dev-ed.develop.file.force.com/sfc/servlet.shepherd/version/renditionDownload?rendition=ORIGINAL_Jpg&versionId='+testContent.Id+'&operationContext=CHATTER&contentId='+testContent.ContentBodyId; } else{ contact.Image_url__c='No profile'; } updatec.add(contact); } update updatec; Test.startTest(); // Call the method to be tested from the Controller class Controller.checkDoc(contentDocumentId, 'Profilejiou'); Test.stopTest(); } @IsTest static void TestControllerMethod2() { Contact con = new Contact(); con.LastName = 'LastName'; insert con; ContentVersion testContent = new ContentVersion(); testContent.Title = 'Profilejiou'; testContent.PathOnClient = 'version.jpg'; testContent.VersionData = Blob.valueOf('Profilejiou'); insert testContent; ContentVersion testContent2 = new ContentVersion(); testContent2.Title = 'Profilejiou12'; testContent2.PathOnClient = 'version2.jpg'; testContent2.VersionData = Blob.valueOf('Profilejiou12'); insert testContent2; Id contentDocumentId = [SELECT ContentDocumentId FROM ContentVersion WHERE Id = :testContent.Id].ContentDocumentId; ContentDocumentLink cdl = new ContentDocumentLink(); cdl.ContentDocumentId = contentDocumentId; cdl.LinkedEntityId = con.Id; insert cdl; Listdc=[SELECT Id FROM ContentDocument WHERE Id=:contentDocumentId]; ContentDistribution link12 = new ContentDistribution(); link12.Name='hiiii'; link12.ContentVersionId =testContent.Id ; insert link12; // ContentDistribution cds = [SELECT DistributionPublicUrl FROM ContentDistribution WHERE Id=:link12.Id]; Listconlist=[SELECT Id,LastName,Profile_Image__c,Image_url__c,Description FROM Contact WHERE Id =:con.Id]; List updateagain = new List(); for (Contact contact : conlist) { contact.Description = 'attachment inserted ftw'; //contact.PublicUrlOfAttachment__c=cds.DistributionPublicUrl; if(testContent.Title.containsIgnoreCase('Profile')) { contact.Image_url__c='https://suprnova-dev-ed.develop.file.force.com/sfc/servlet.shepherd/version/renditionDownload?rendition=ORIGINAL_Jpg&versionId='+testContent.Id+'&operationContext=CHATTER&contentId='+testContent.ContentBodyId; } else{ contact.Image_url__c='No profile'; } updateagain.add(contact); } update updateagain; Test.startTest(); // Call the method to be tested from the Controller class Controller.deletemethod(dc); Test.stopTest(); } }