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 

An Apex error occurred: System.NullPointerException: Attempt to de-reference a null object in process builder

 I have created apex with process builder while doing process it throws error any help me out.

 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.sendAnEmail();
    }
      
    private static  Application__c account;
     public static void sendAnEmail() {
            system.debug('--check-'+ApexPages.currentPage().getParameters().get('QuoteHeaderid') );
            try{
        account = [SELECT Id, Name  FROM Application__c 
                   WHERE Id = :ApexPages.currentPage().getParameters().get('id')];
               
    }
            catch (Exception e) {
   
    account = new Application__c();
}
        }
        public static Application__c getAccount() {
        return account;
    }

}

User-added image
SwethaSwetha (Salesforce Developers) 
Duplicate of https://developer.salesforce.com/forums/ForumsMain?id=9062I000000DIuu
Pike MoPike Mo
NullPointerException: Attempt to de-reference a null object is very common error in apex class. It occurs when your variable (sobject, list, set or any other data type) is not initialized (allocated memory). ... This error may occur in Apex classes, Visualforce pages with Apex controller, Test classes, Apex Triggers. you can check it via (https://assignmenthelpsaustralia.com/services/assignment-help-melbourne.php