I am trying to call a method from a trigger that will generate a pdf whenever any order(object) record is created. I wrote a after insert, after updated trigger and called the method for pdf generation like below.
for (Order_vod__c ord : trigger.new) { if (ord != null) { PDFExport_OrderDetails exp= new PDFExport_OrderDetails(); exp.send_order_pdf(ord.id); } } //method body public PageReference send_order_pdf(Id ordId) { List<String> toAddress = new List<String>(); String orderId ; if(ApexPages.currentPage().getParameters().get('Id') != null) { orderId = ApexPages.currentPage().getParameters().get('Id'); } Order_vod__c order =[SELECT Id,Name,Owner.Email,Account_vod__r. Email__c From Order_vod__c WHERE Id=:orderId ]; Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage(); PageReference pdf; pdf = new PageReference('/apex/View_Order_vod?id='+orderId); pdf.getParameters().put('id',orderId); pdf.setRedirect(true); Blob b = pdf.getContent(); System.debug('Blob ****'+b); Messaging.EmailFileAttachment fileAttachmt = new Messaging.EmailFileAttachment(); fileAttachmt.setFileName('attachment.pdf'); fileAttachmt.setBody(b); System.debug('fileAttachmt****'+fileAttachmt); String address ; if(order.Owner.Email!= null) { address= order.Owner.Email; } //String[] toAddress=address.split(',',0); System.debug('Rep email id****'+address); toAddress.add(address); toAddress.add('[email protected]'); email.setToAddresses(toAddress); System.debug('email*****'+email); email.setPlainTextBody('Please find the Order'+order.Name+' as an attachment'); email.setFileAttachments(new Messaging.EmailFileAttachment[] {fileAttachmt}); // Sends the email Messaging.SendEmailResult [] r = Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email}); return null; } but I am getting an error "System.NullPointerException: Attempt to de-reference a null object". Although I kept the checking ord != null, not sure what is causing this error. Kindly suggest.
nulldereference? What debug output are you seeing?ordis never going to benullas the trigger wouldn't process a null record reference.