You need to sign in to do that
Don't have an account?
salesforce fatal error
Hello,
I have an apex Emthod which calls a VF Page as a PDF and inserts the PDF to a record. Right now it is working as long as I don't call any Contact info for use in the PDF. As you can see in the VF Page I am trying to access the First Name of the Contact. The Error Log below I started where it starts looking at the PDF, then through where the Fatal Error comes in. The VF Page and Apex, I put in some comments in line. I have a feeling running the Method as static void has something to do with the error? Any suggestions much appreciated!!
Thanks,
Ryan
Error Log:
I have an apex Emthod which calls a VF Page as a PDF and inserts the PDF to a record. Right now it is working as long as I don't call any Contact info for use in the PDF. As you can see in the VF Page I am trying to access the First Name of the Contact. The Error Log below I started where it starts looking at the PDF, then through where the Fatal Error comes in. The VF Page and Apex, I put in some comments in line. I have a feeling running the Method as static void has something to do with the error? Any suggestions much appreciated!!
Thanks,
Ryan
Error Log:
13:02:11.430 (5727412584)|STATEMENT_EXECUTE|[95] 13:02:11.430 (5727438344)|HEAP_ALLOCATE|[95]|Bytes:16 13:02:11.430 (5727493424)|VARIABLE_SCOPE_BEGIN|[95]|pdfPage|System.PageReference|true|false 13:02:11.430 (5728228256)|VARIABLE_ASSIGNMENT|[95]|pdfPage|"/apex/contactpdf"|0x70a80652 13:02:11.430 (5728244984)|STATEMENT_EXECUTE|[96] 13:02:11.430 (5728274749)|SYSTEM_METHOD_ENTRY|[96]|System.PageReference.getParameters() 13:02:11.430 (5728318848)|HEAP_ALLOCATE|[96]|Bytes:0 13:02:11.430 (5728348187)|SYSTEM_METHOD_EXIT|[96]|System.PageReference.getParameters() 13:02:11.430 (5728361632)|HEAP_ALLOCATE|[96]|Bytes:2 13:02:11.430 (5728411478)|SYSTEM_METHOD_ENTRY|[96]|Map<String,String>.put(Object, Object) 13:02:11.430 (5728453867)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:-4 13:02:11.430 (5728478883)|SYSTEM_METHOD_EXIT|[96]|Map<String,String>.put(Object, Object) 13:02:11.430 (5728490327)|STATEMENT_EXECUTE|[97] 13:02:11.430 (5728519858)|VARIABLE_SCOPE_BEGIN|[97]|pdfBody|Blob|false|false 13:02:11.430 (5728539640)|VARIABLE_ASSIGNMENT|[97]|pdfBody|null 13:02:11.430 (5728561572)|METHOD_ENTRY|[99]||System.Test.isRunningTest() 13:02:11.430 (5728593511)|METHOD_EXIT|[99]||System.Test.isRunningTest() 13:02:11.430 (5728603950)|STATEMENT_EXECUTE|[101] 13:02:11.430 (5728606748)|STATEMENT_EXECUTE|[102] 13:02:11.430 (5728618628)|SYSTEM_METHOD_ENTRY|[102]|System.PageReference.getContentAsPDF() 13:02:11.430 (5797457576)|FATAL_ERROR|Internal Salesforce.com ErrorVF Page:
<apex:page standardController="Contact" applyBodyTag="false" renderAs="pdf"> <!--CSS Styling Removed--> <html> <body> <!-- Breaks when trying to pull Contact First Name. If I do not pull the first name Apex and VF Page run perfectly --> I, {!Contact.FirstName} acknowledge blah blah blahApex:
public class EchoSignRG{ public ApexPages.StandardController Controller; public EchoSignRG(ApexPages.StandardController Controller){ this.Controller = Controller;} @InvocableMethod public static void SendPDF(List<ID> conid){ Lead L = [SELECT Id,Name,Street,City,State,PostalCode,ConvertedContactId,ConvertedOpportunityId,LeadSource,ConvertedAccountId FROM Lead WHERE Id =: conid]; Contact con1 = [SELECT Id,AccountId,email,Firstname,lastname FROM Contact WHERE Id =: L.ConvertedContactId]; //SOME OTHER CODE HERE pageReference pdfPage = Page.ContactPDF; pdfPage.getParameters().put('id',con1.Id); blob pdfBody; if(Test.isRunningTest()){ pdfBody = blob.valueOf('Unit.Test'); }else{ pdfBody = pdfPage.getContentAsPDF();} //Fatal Error LINE ABOVE attachment pdfFile = new attachment(); pdfFile.isPrivate = false; pdfFile.body = pdfBody; pdfFile.parentId = agreementRec1.id; pdfFile.Name = agreementRec1.Name+'.pdf'; insert pdfFile;
The Issue was with the null check.If no contact then it is failing. Updated code is here
Sorry, didn't work. In this case, the Contact will always be populated. This Apex is run upon Lead conversion. So it will always convert the Lead to a Contact.