Controller:
`global class FireHydrantTestTempController { public Id inspectionId { get; set; } public Id documentId { get; set; }
public FireHydrantTestTempController() {
try {
system.debug('Inspection Id' + this.inspectionId);
Document docList = [SELECT Id, Name, CreatedDate, Body, Keywords FROM Document WHERE Keywords = :this.inspectionId ORDER BY CreatedDate DESC LIMIT 1];
documentId = docList.id;
} catch (Exception e) {
system.debug('An error occurred while querying the document: ' + e.getMessage());
documentId = null;
}
}
}
Test Class:
@isTest
public class FireHydrantTestTempControllerTest {
static testMethod void testGetDocument() {
test.startTest();
Inspection_Report__c testInspectionReport = TestDataFactory.getInspectionReportdata();
//ContentVersion testContentVersion = TestDataFactory.getInspectionReport1();
Document document = new Document();
document.Body = Blob.valueOf('Some Text');
document.ContentType = 'application/pdf';
document.DeveloperName = 'my_document';
document.IsPublic = true;
document.Keywords = testInspectionReport.Id;
document.Name = 'My Document';
document.FolderId = UserInfo.getUserId();
insert document;
FireHydrantTestTempController controller = new FireHydrantTestTempController();
//Test.setCurrentPage(Page.FireHydrantTestTempComponent);
controller.inspectionId = testInspectionReport.Id;
controller.documentId = document.Id;
System.assertEquals(document.Id,controller.documentId);
test.stopTest();
}
}`
vF component:
`<apex:component controller="FireHydrantTestTempController" access="global" >
<apex:attribute name="docId" type="Id" description="Id of the document" assignTo="{!inspectionId}"/>
<html>
<div style="clear:both;height:25px;"></div>
<apex:image value="/servlet/servlet.FileDownload?file={!documentId}" style="width:100%;"/>
</html>
</apex:component> `
Facing Issue while sending the mail and graph is not visible after email is sent I am trying to display graph in email using email template but i am getting inspection ID null in controller while sending the mail.
Graph is not visible in the email, instead of graph image it is sending another document image as Inspection Id is null.