• Dominic Bird
  • NEWBIE
  • 10 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 5
    Replies
I have created a visualforce page for rendering contracts as PDFs. This all works very well, but I have no way of catching errors before rendering as a PDF.

At the moment I just display pagemessages in the exported PDF and have styled the, which isn't very pretty.
 
<html>
    <div class="error">
    <apex:pageMessages id="error"/>
    </div>
    <body>

What I really want is it catch pageMessages, and if there are any, don't render as a PDF and just show a popup instead. Can I do this on a visual force page? I'm assuming I can do some kind of if statement that will set renderAs to HTML or advanced_pdf if the length of pageMessages > 0, but I'm sure how I would do that on a visualforce page. Currently I just have a button that renders my visualforce. My controller extension is what checks for missing data and will return an error.
 
<apex:page standardController="Contract" renderAs="advanced_pdf" extensions="ContractsLookup" standardStylesheets="false" applyBodyTag="false" applyHtmlTag="false" showHeader="false">
  <!-- Page Header -->

Any ideas appreciated.
 
Hi all,

I'm attempting to create a a very simple apex test for a controller extension that just lookups some values for rendering PDFs. I get the following compile error:
Error: Compile Error: Invalid type: ContractLookups at line 25 column 9
The controller works fine in my visualforce pages. I just need to test it but failing at the first hurdle.

Controller Extension:
public class ContractsLookup {
    // set public variables
    
    public Contract con {get;set;} 
    public Contract contract_lu {get;set;}
    public Account account_lu{get;set;}
    public Contact contact_lu{get;set;}
    public User user_lu{get;set;}
    
    //Constructors
    public ContractsLookup(ApexPages.StandardController std) {
        // Lookup contract
        con = (contract)std.getRecord();

        // Lookup various IDs from contract
        contract_lu = [SELECT AccountID,CustomerSignedId,CompanySignedId FROM Contract WHERE Id = :con.Id];
        
        // get related Account
        account_lu = [SELECT Name FROM Account WHERE Id = :contract_lu.AccountId LIMIT 1];
        
        // get related Contact
        contact_lu = [SELECT Name FROM Contact WHERE Id = :contract_lu.CustomerSignedId LIMIT 1];
       
       // get related Users
       user_lu = [SELECT Name FROM User WHERE Id = :contract_lu.CompanySignedId LIMIT 1];
    }
}

Test
@isTest
public class ContractLookupsTest {
    public static testMethod void testMyController() {
    
            
        //Create account and contract for controller
        Account testAccount = new Account();
        testAccount.Name='Test Account' ; 
        insert testAccount;
        
        Contract cont = new Contract();
        cont.Accountid= testAccount.id;
        insert cont;
        
        
        //Test current page
        Test.setCurrentPage(Page.NewAccountAndContract);

        
        //create a standard controller and pass it contract
        ApexPages.StandardController contractController = new ApexPages.StandardController(cont);


        //Add the controller extension
        ContractLookups lookups = new ContractLookups(contractController);
        }
}

Any ideas?
I have created a visualforce page for rendering contracts as PDFs. This all works very well, but I have no way of catching errors before rendering as a PDF.

At the moment I just display pagemessages in the exported PDF and have styled the, which isn't very pretty.
 
<html>
    <div class="error">
    <apex:pageMessages id="error"/>
    </div>
    <body>

What I really want is it catch pageMessages, and if there are any, don't render as a PDF and just show a popup instead. Can I do this on a visual force page? I'm assuming I can do some kind of if statement that will set renderAs to HTML or advanced_pdf if the length of pageMessages > 0, but I'm sure how I would do that on a visualforce page. Currently I just have a button that renders my visualforce. My controller extension is what checks for missing data and will return an error.
 
<apex:page standardController="Contract" renderAs="advanced_pdf" extensions="ContractsLookup" standardStylesheets="false" applyBodyTag="false" applyHtmlTag="false" showHeader="false">
  <!-- Page Header -->

Any ideas appreciated.
 
Hi all,

I'm attempting to create a a very simple apex test for a controller extension that just lookups some values for rendering PDFs. I get the following compile error:
Error: Compile Error: Invalid type: ContractLookups at line 25 column 9
The controller works fine in my visualforce pages. I just need to test it but failing at the first hurdle.

Controller Extension:
public class ContractsLookup {
    // set public variables
    
    public Contract con {get;set;} 
    public Contract contract_lu {get;set;}
    public Account account_lu{get;set;}
    public Contact contact_lu{get;set;}
    public User user_lu{get;set;}
    
    //Constructors
    public ContractsLookup(ApexPages.StandardController std) {
        // Lookup contract
        con = (contract)std.getRecord();

        // Lookup various IDs from contract
        contract_lu = [SELECT AccountID,CustomerSignedId,CompanySignedId FROM Contract WHERE Id = :con.Id];
        
        // get related Account
        account_lu = [SELECT Name FROM Account WHERE Id = :contract_lu.AccountId LIMIT 1];
        
        // get related Contact
        contact_lu = [SELECT Name FROM Contact WHERE Id = :contract_lu.CustomerSignedId LIMIT 1];
       
       // get related Users
       user_lu = [SELECT Name FROM User WHERE Id = :contract_lu.CompanySignedId LIMIT 1];
    }
}

Test
@isTest
public class ContractLookupsTest {
    public static testMethod void testMyController() {
    
            
        //Create account and contract for controller
        Account testAccount = new Account();
        testAccount.Name='Test Account' ; 
        insert testAccount;
        
        Contract cont = new Contract();
        cont.Accountid= testAccount.id;
        insert cont;
        
        
        //Test current page
        Test.setCurrentPage(Page.NewAccountAndContract);

        
        //create a standard controller and pass it contract
        ApexPages.StandardController contractController = new ApexPages.StandardController(cont);


        //Add the controller extension
        ContractLookups lookups = new ContractLookups(contractController);
        }
}

Any ideas?

Hello everyone,

I am having an issue with the renderAs=pdf functionality using Visualforce pages.

We often have ordered lists that are broken and are restarted, so <ol start="num"> is used.

It does not look like Visualforce pages while rendered as PDFs respect the start attribute.

Example code:

<ol>
<li> List Item 1</li>
<li>List Item 2</li>
</ol>
<apex:image src="src"></apex:image>
<ol start="3">
<li>List Item 3</li>
</ol>

Should be displayed like this:
1. List Item 1
2. List Item 2
{{IMAGE HERE}}
3. List Item 3

Instead it is displayed like this:
1. List Item 1
2. List Item 2
{{IMAGE HERE}}
1. List Item 3


Is there something that could be done to get around this? We have a need to dynamically create PDFs of Knowledge Articles so it needs to dynamically load the content of the Knowledge Article that is passed to it.

Thanks