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 

pdf merge fields not working on @invokablemethod in Process builder

  1. I have the Application__c object with the lookup contact object.
  2. I need to show the Contact name and application Name in pdf which I have created
  3. I have used the Invocable method for sending emails with pdf...
  4. when I do the process it throws an error Like this below:
Error Occurred: common.apex.runtime.impl.ExecutionException: List has no rows for assignment to SObject

But now I unable to show any merged field on my pdf page. There is any resolved solution?
<apex:page controller="sendAnEmail" renderAs="pdf">
   <apex:form >
           You belong to Contact Name:{!account.name} 
             
    </apex:form> 
  <h1>
      hello
    </h1>
</apex:page>
 
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 FROM Application__c WHERE Id IN :listofQuoteHeader]);
           for(Id QuoteHeaderid :listofQuoteHeader)
           {
               PageReference pref= page.PDFGEN;
               pref.getParameters().put('id',(Id)QuoteHeaderid);
               pref.setRedirect(true);
               
               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);
           } }
      
      private final Application__c account;
        public sendAnEmail() {
            system.debug('---'+ApexPages.currentPage().getParameters().get('id') );
        account = [SELECT Id, Name  FROM Application__c 
                   WHERE Id = :ApexPages.currentPage().getParameters().get('id')];
    }
        public Application__c getAccount() {
        return account;
    }

}

User-added image