function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
chikkuchikku 

Error Occurred: An Apex error occurred: System.NullPointerException: Attempt to de-reference a null object

I don't know where I made mistake in the apex with process builder help me out
While debugging the error shown in 48 lines of the apex

Error:Error Occurred: An Apex error occurred: System.NullPointerException: Attempt to de-reference a null object
 
public class sendAnEmail
{
    

    @InvocableMethod(label='Test' description='sends an email')
       
    public static void sendEmailWithAttachment(List<id> listofQuoteHeader)
    {   
        
     
        Map<Id, Application__c> quotesMap =  new Map<Id, Application__c>([SELECT id,Contact__r.Email,Contact__r.Name FROM Application__c WHERE Id IN :listofQuoteHeader]);
           for(Id QuoteHeaderid :listofQuoteHeader)
           {
               PageReference pref= page.PDFGEN;
               pref.getParameters().put('id',(Id)QuoteHeaderid);
               pref.setRedirect(true);
                system.debug('--appID-'+QuoteHeaderid);
               Attachment attachment = new Attachment();      
               Blob b=pref.getContentAsPDF();
               attachment.Body = b;
               attachment.Name = Datetime.now().format('yyyy-MM-dd HH:mm') + ' ' + 'Quote' + '.pdf';
               attachment.IsPrivate = false;
               attachment.ParentId = QuoteHeaderid;
               attachment.Name='Sign.png';
               insert attachment;
               
               Messaging.SingleEmailMessage semail= new Messaging.SingleEmailMessage();
               Messaging.EmailFileAttachment attach= new Messaging.EmailFileAttachment();
               attach.setFileName('AttachmentEmailFile.pdf');
               attach.setBody(b);
               semail.setSubject('Quote Issued');
            //    String[] emailIds= new String[]{'abc@gmail.com'}; 
            String[] emailIds= new String[]{quotesMap.get(QuoteHeaderid)?.Contact__r.Email};
               semail.setToAddresses(emailIds);
               
               semail.setPlainTextBody('Please find the attached quote details');
               semail.setFileAttachments(new Messaging.EmailFileAttachment[]{attach});
        Messaging.sendEmail(new Messaging.SingleEmailMessage[]{semail});
                  system.debug('----'+listofQuoteHeader);
           } 
        
     SendAnEmail.test();
    }
       public Application__c account{get;set;} 
      
    private static  Application__c account;
     public static void test() {
            system.debug('--check-'+ApexPages.currentPage().getParameters().get('QuoteHeaderid') );
            try{
                 if (account != null) 

        account = [SELECT Id, Name  FROM Application__c 
                  Where Id=:ApexPages.currentPage().getParameters().get('Id')];// i think this part shwoing error while debug
               
    }
            catch (Exception e) {
   
    account = new Application__c();
}
        }
        public static Application__c getAccount() {
        return account;
    }

}

User-added image
SwethaSwetha (Salesforce Developers) 
HI Chikku,
Can you put a system.debug statement in the try block where you highlighted in bold. Also, what does it show for the below debug statement of your code? 
system.debug('--check-'+ApexPages.currentPage().getParameters().get('QuoteHeaderid') );

Thanks