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
Felix QuinonesFelix Quinones 

Why my ApexPage code is not producing a Visualforce PDF page with BOLD headings? ApexPage and ApexTrigger Issues

Hello All, 

I created an ApexPage and an ApexTrigger. 

The ApexPage takes information from the Opportunity Object to create a PDF. That PDF should be automatically sent to an email every time the opportunity Stage is marked as "Vetting". 

The code for my ApexPage named "NewGrantOpportunity" is not converting heading 2 (H2) into bold. What I'm doing wrong?

ApexPage Code: 

<apex:page standardController="Opportunity" renderAs="pdf">
  <head>
    <style>
    .bold {
      font-weight: bold;
    }
    </style>
  </head>

  <h1>New Grant Opportunity</h1>
  <h2>Funding Opportunity Detail</h2>
  <br />
  <apex:outputLabel value="Opportunity ID: " for="opportunityId" styleClass="bold"/>
  <apex:outputField id="opportunityId" value="{!Opportunity.Id}"/>
  <br />
  <apex:outputLabel value="Opportunity Name: " for="opportunityName" styleClass="bold"/>
  <apex:outputField id="opportunityName" value="{!Opportunity.Name}"/>
  <br />
  <apex:outputLabel value="Description: " for="description" styleClass="bold"/>
  <apex:outputField id="description" value="{!Opportunity.RecordType.Description}"/>
  <br />
  <apex:outputLabel value="Notification Date: " for="notificationDate" styleClass="bold"/>
  <apex:outputField id="notificationDate" value="{!Opportunity.Notification_Date__c}"/>
  <br />
  <apex:outputLabel value="Deadline (Close Date): " for="closeDate" styleClass="bold"/>
  <apex:outputField id="closeDate" value="{!Opportunity.CloseDate}"/>
  <br />
  <apex:outputLabel value="Funding Area: " for="fundingArea" styleClass="bold"/>
  <apex:outputField id="fundingArea" value="{!Opportunity.npsp__Grant_Program_Area_s__c}"/>
  <br />
  <apex:outputLabel value="Award Amount: " for="awardAmount" styleClass="bold"/>
  <apex:outputField id="awardAmount" value="{!Opportunity.Award_Amount__c}"/>
  <br />
  <h2>Account Information</h2>
  <apex:outputLabel value="Funder Name: " for="funderName" styleClass="bold"/>
  <apex:outputField id="funderName" value="{!Opportunity.Account.Name}"/>
  <br />
  <apex:outputLabel value="Funder Area: " for="funderArea" styleClass="bold"/>
  <apex:outputField id="funderArea" value="{!Opportunity.Programs__c}"/>
  <br />
  <apex:outputLabel value="Type: " for="type" styleClass="bold"/>
  <apex:outputField id="type" value="{!Opportunity.Account.Type}"/>
  <br />
  <apex:outputLabel value="Primary Contact: " for="primaryContact" styleClass="bold"/>
  <apex:outputField id="primaryContact" value="{!Opportunity.npsp__Primary_Contact__r.Name}"/>
  <br />
  <apex:outputLabel value="Website: " for="website" styleClass="bold"/>
  <apex:outputField id="website" value="{!Opportunity.npsp__Grant_Requirements_Website__c}" />
  <br />
  <h2>Program Design and Budget Information</h2>
  <apex:outputLabel value="Grant Eligibility: " for="grantEligibility" styleClass="bold"/> 
  <apex:outputField id="grantEligibility" value="{!Opportunity.Grant_Eligibility__c}"/>
  <br />
  <apex:outputLabel value="Program Goals: " for="programGoals" styleClass="bold"/> 
  <apex:outputField id="programGoals" value="{!Opportunity.Grant_Goals__c}"/>
  <br />
  <apex:outputLabel value="Use of Funds: " for="useOfFunds" styleClass="bold"/> 
  <apex:outputField id="useOfFunds" value="{!Opportunity.Use_of_Funds__c}"/>
  <br />
  <h2>Strategic Information</h2>
  <apex:outputLabel value="Funding Source: " for="fundingSource" styleClass="bold"/>   
  <apex:outputField id="fundingSource" value="{!Opportunity.Funding_Source__c}"/>
  <br />
  <apex:outputLabel value="Strategic Alignment: " for="strategicAlignment" styleClass="bold"/>   
  <apex:outputField id="strategicAlignment" value="{!Opportunity.Strategic_Alignment__c}"/>
  <br />
  <apex:outputLabel value="Fiscal Year: " for="fiscalYear" styleClass="bold"/> 
  <apex:outputField id="fiscalYear" value="{!Opportunity.Fiscal_Year__c}"/>
  <br />
  <apex:outputLabel value="Stage: " for="Stage" styleClass="bold"/> 
  <apex:outputField id="Stage" value="{!Opportunity.StageName}"/>
  <br />
  <h2>Vetting Process</h2>
  <apex:outputLabel value="Select the checkmark if the opportunity was reviewed and was approved as prospecting: " for="vetted" styleClass="bold"/>   
  <apex:outputField id="vetted" value="{!Opportunity.Vetted_Grant__c}"/>
</apex:page>

Similarly, my ApexTrigger named "PDFGenerator" is not generating an automatic email. 

ApexTrigger Code: 
 

public class PDFGenerator {
  public static void sendPDF(Id opportunityId) {
    // Query the opportunity record
    Opportunity opportunity = [SELECT Id, Name FROM Opportunity WHERE Id = :opportunityId];

    // Generate the PDF attachment
    PageReference pdf = Page.NewGrantOpportunity;
    pdf.getParameters().put('id', opportunity.Id);
    Blob pdfBlob = pdf.getContentAsPDF();
    String fileName = opportunity.Name + '.pdf';
    Messaging.EmailFileAttachment pdfAttachment = new Messaging.EmailFileAttachment();
    pdfAttachment.setFileName(fileName);
    pdfAttachment.setBody(pdfBlob);

    // Set up the email message
    Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
    email.setToAddresses(new String[] {'grants@EXAMPLE.org'});
    email.setSubject('New Grant Opportunity PDF: {!relatedTo.Name}');
    email.setPlainTextBody('A new opportunity was created with the name {!Opportunity.Name}.');
    email.setTemplateId('00EXAMPLEiEAG');
    email.setTargetObjectId(opportunity.Id);  
    email.setFileAttachments(new Messaging.EmailFileAttachment[] { pdfAttachment });

    // Send the email
    Messaging.sendEmail(new Messaging.SingleEmailMessage[] { email });
  }
}
I appreciate your help in advance. 

 

AnkaiahAnkaiah (Salesforce Developers) 
Hi Felix,

I have tested the same code and its working fine.

Refer the below screenshot.

User-added image
Thanks!!
 
Felix QuinonesFelix Quinones
Thank you. I was able to modify the code.