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 

Unable to show merge fields in Vf page

  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 apex controller for merged class it doesn't work
But now I unable to show any merged field on my pdf page. There is any resolved solution? it may help others too.
 
<apex:page renderAs="PDF" >
    <h1 >Congratulations </h1 >
Name:Application__c.Contact__r.Nam
 
 </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});
           }
       
            }
  }

 
ANUTEJANUTEJ (Salesforce Developers) 
Hi Chikku,

Can you try checking if the API name is proper?

Also please try checking the below link.

>> https://salesforce.stackexchange.com/questions/227476/what-are-merge-fields-in-apex-and-why-are-the-called-so

For quick reference I am adding a part of the best answer stated for quick reference:

The most typical use case is to "bind" an element to an attribute. For example, we often write code like this:

<apex:inputField value="{!Account.Name}" />

Which tells Visualforce that the Account.Name field should be rendered as an input text, and honor field level security.

Note that merge fields are used throughout Salesforce: Custom Buttons and Links, Visualforce, Apex Code, Lightning Components, Flows, and many other features. Most of them look like {!...}, but there are some special exceptions, so whenever you're not sure, make sure you check the documentation.

Let me know if it helps you and close your query by marking it as solved so that it can help others in the future.  

Thanks.