• Cyril Caton
  • NEWBIE
  • 50 Points
  • Member since 2012

  • Chatter
    Feed
  • 2
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 4
    Replies

I have a VF page that I am rendering in PDF where part of the content is an Ordered List, with some embedded Unordered Lists. When I use the renderas="pdf" argument in my apex:page line the embedded lists do not render correctly. If I take out the renderas="pdf" argument in the apex:page line, the resulting HTML page does render correctly.

 

Here is an example VF page:

 

<apex:page standardController="Opportunity" sidebar="false"
    showheader="false" cache="true" renderas="pdf">
<HTML>
<head></head>
<body>
    <P>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam rutrum est in elit volutpat 
    lacinia. Integer scelerisque enim eu quam tempor in sagittis urna consequat. Morbi euismod, 
    quam nec malesuada lacinia, erat elit varius metus, in vehicula nisl nibh non leo.</P>
    <OL>
        <LI>Curabitur vel euismod est. Nunc id ligula dui, at mollis risus:
        <UL>
            <LI>Morbi ultrices feugiat leo, ut luctus augue lobortis eget;</LI>
            <LI>Vestibulum dignissim risus at turpis pretium ut facilisis dolor bibendum.</LI>
        </UL>
        </LI>
        <LI>IAliquam aliquam porta tellus, sit amet tempor ligula lobortis vitae:
        <UL>
            <LI>Nunc suscipit dui vitae dui sagittis non scelerisque sem ultrices;</LI>
            <LI>Fusce sit amet lorem sed metus tincidunt tristique;</LI>
            <LI>Cras rutrum enim ac ipsum ullamcorper scelerisque</LI>
        </UL>
        </LI>
        <LI>Aenean eu neque mattis nibh viverra facilisis viverra ac sapien. Integer 
            sed mauris at nibh volutpat varius ac volutpat dolor.</LI>
        <LI>Vestibulum euismod ipsum sed eros faucibus laoreet arius diam sit amet 
             metus venenatis nec imperdiet nibh dapibus.</LI>
    </OL>
    <P>Aliquam luctus turpis non lectus rhoncus non hendrerit eros facilisis. Nulla facilisi. 
    Nunc blandit tortor id nisl egestas semper tristique nunc cursus. Donec vulputate venenatis mi, 
    vitae pretium nisl dapibus eu. Sed purus nisi, malesuada in imperdiet ac, rhoncus sit amet velit. 
    Sed a quam nec lorem consectetur bibendum ut quis augue. Mauris et nulla eget purus sodales 
    tempor vitae at diam.</P> 
</body>
</html> 
</apex:page>

 The rendered PDF page shows as follows:

 

 

 

 

Whereas if I remove the renderas="pdf" in the apex:page line and let the page render as HTML, I get the following result:

 

 

 

Seems like the PDF render within VF is not producing reasonable output results for this example.

 

Has anyone else seen this type of issue?  Is there any way to weork around the problem?

Hi everyone,

 

I'm trying to allow a user to upload an image in a specific directory, and keep a reference to that image in a custom setting parameter. So far, nothing too complicated.

 

To do that, I display the current image, I make it clickable. On click, a pop-up window shows up, with the classic "select file" button that helps you select a file from your hard-drive, and a validate button loading the image and updating the custom setting parameter.

 

My issue: the image loading only works ... every second time I try to do it! Basically, I open the pop-up window, select a file, validate: nothing happens and the pop-up window stays open. Select the same file, validate: here you go, my file is getting uploaded and parameter gets updated. 

 

Here is the code. Note: I left the debug message in the controller. First time I try to upload the image, I see 'body is null' in the logs. Second time, everything works fine.

 

Thanks for your help!

 

VF page

  
<apex:actionFunction name="showPopUp" action="{!showPopup}" rerender="popup" />

<apex:image id="logo" value="{!myTemplate.URL_Logo__c}" styleClass="logo" alt="Logo" onclick="showPopUp();return false;" /> <!-- Pop-up allowing to select a new file --> <apex:outputPanel id="popup"> <apex:outputPanel styleClass="customPopup" layout="block" rendered="{!displayPopUp}"> <h2>Sélectionner votre logo</h2> <br /><apex:inputFile value="{!document.body}" filename="{!document.name}"/> <apex:commandButton value="Valider" action="{!doUpload}" /> </apex:outputPanel> </apex:outputPanel>

 

Custom Controller

public Document document
{
	get
	{
		if(document==null)
		{
			document = new Document();
		}
		return document;
	}
	set;
}

public Raison_Sociale__c myRaisonSociale {get;set;}

public boolean displayPopup {get; set;}

public void closePopup() {
	displayPopup = false;
}

public void showPopup() {
	displayPopup = true;
} 

(...)

//Uploading an image in a specific Document directory
public PageReference doUpload() 
{
	if (document.body != null) {
		system.debug('body is not null');
		if (document.name != null) {
			system.debug('name is not null');
			Document d = document;
			//Looking for the Document directory named Logos Factures               
			Folder[] folders = [select id from Folder where name='Logos_Facture'];
			if (folders.isEmpty()) {
				system.debug('Did not find Logos_Factures directory');
				d.folderid = UserInfo.getUserId(); //store in Personal Documents
			} else {
				system.debug('found Logos_Factures directory');
				d.folderId = folders[0].id;
			}
			//Making the document available to everyone
			d.IsPublic = true;
			try {
				insert d;
				system.debug('insert doc ok');
				system.debug('BEFORE: template url logo = ' + myTemplate.URL_Logo__c);
				myTemplate.URL_Logo__c = DocumentUtil.getInstance().getURL(d);
				system.debug('AFTER: template url logo = ' + myTemplate.URL_Logo__c);
				update myTemplate;
				system.debug('update url logo ok');
			} catch (Exception e) {
				ApexPages.addMessages(e);
				system.debug('Problem inserting the document or updating the template: ' + e);
			}  

			d.body = null;
			
			//Adding redirection if using the pop-up module
			//so the page gets refreshed since rerender is not supported
			PageReference curPage = ApexPages.currentPage();
			curPage.setRedirect(true);
			return curPage;
		} else {
			system.debug('name is null');
		}
	} else {
		system.debug('body is null');
	}

	return null;
}

 

 

I have a VF page that I am rendering in PDF where part of the content is an Ordered List, with some embedded Unordered Lists. When I use the renderas="pdf" argument in my apex:page line the embedded lists do not render correctly. If I take out the renderas="pdf" argument in the apex:page line, the resulting HTML page does render correctly.

 

Here is an example VF page:

 

<apex:page standardController="Opportunity" sidebar="false"
    showheader="false" cache="true" renderas="pdf">
<HTML>
<head></head>
<body>
    <P>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam rutrum est in elit volutpat 
    lacinia. Integer scelerisque enim eu quam tempor in sagittis urna consequat. Morbi euismod, 
    quam nec malesuada lacinia, erat elit varius metus, in vehicula nisl nibh non leo.</P>
    <OL>
        <LI>Curabitur vel euismod est. Nunc id ligula dui, at mollis risus:
        <UL>
            <LI>Morbi ultrices feugiat leo, ut luctus augue lobortis eget;</LI>
            <LI>Vestibulum dignissim risus at turpis pretium ut facilisis dolor bibendum.</LI>
        </UL>
        </LI>
        <LI>IAliquam aliquam porta tellus, sit amet tempor ligula lobortis vitae:
        <UL>
            <LI>Nunc suscipit dui vitae dui sagittis non scelerisque sem ultrices;</LI>
            <LI>Fusce sit amet lorem sed metus tincidunt tristique;</LI>
            <LI>Cras rutrum enim ac ipsum ullamcorper scelerisque</LI>
        </UL>
        </LI>
        <LI>Aenean eu neque mattis nibh viverra facilisis viverra ac sapien. Integer 
            sed mauris at nibh volutpat varius ac volutpat dolor.</LI>
        <LI>Vestibulum euismod ipsum sed eros faucibus laoreet arius diam sit amet 
             metus venenatis nec imperdiet nibh dapibus.</LI>
    </OL>
    <P>Aliquam luctus turpis non lectus rhoncus non hendrerit eros facilisis. Nulla facilisi. 
    Nunc blandit tortor id nisl egestas semper tristique nunc cursus. Donec vulputate venenatis mi, 
    vitae pretium nisl dapibus eu. Sed purus nisi, malesuada in imperdiet ac, rhoncus sit amet velit. 
    Sed a quam nec lorem consectetur bibendum ut quis augue. Mauris et nulla eget purus sodales 
    tempor vitae at diam.</P> 
</body>
</html> 
</apex:page>

 The rendered PDF page shows as follows:

 

 

 

 

Whereas if I remove the renderas="pdf" in the apex:page line and let the page render as HTML, I get the following result:

 

 

 

Seems like the PDF render within VF is not producing reasonable output results for this example.

 

Has anyone else seen this type of issue?  Is there any way to weork around the problem?

Hi everyone,

 

I'm trying to allow a user to upload an image in a specific directory, and keep a reference to that image in a custom setting parameter. So far, nothing too complicated.

 

To do that, I display the current image, I make it clickable. On click, a pop-up window shows up, with the classic "select file" button that helps you select a file from your hard-drive, and a validate button loading the image and updating the custom setting parameter.

 

My issue: the image loading only works ... every second time I try to do it! Basically, I open the pop-up window, select a file, validate: nothing happens and the pop-up window stays open. Select the same file, validate: here you go, my file is getting uploaded and parameter gets updated. 

 

Here is the code. Note: I left the debug message in the controller. First time I try to upload the image, I see 'body is null' in the logs. Second time, everything works fine.

 

Thanks for your help!

 

VF page

  
<apex:actionFunction name="showPopUp" action="{!showPopup}" rerender="popup" />

<apex:image id="logo" value="{!myTemplate.URL_Logo__c}" styleClass="logo" alt="Logo" onclick="showPopUp();return false;" /> <!-- Pop-up allowing to select a new file --> <apex:outputPanel id="popup"> <apex:outputPanel styleClass="customPopup" layout="block" rendered="{!displayPopUp}"> <h2>Sélectionner votre logo</h2> <br /><apex:inputFile value="{!document.body}" filename="{!document.name}"/> <apex:commandButton value="Valider" action="{!doUpload}" /> </apex:outputPanel> </apex:outputPanel>

 

Custom Controller

public Document document
{
	get
	{
		if(document==null)
		{
			document = new Document();
		}
		return document;
	}
	set;
}

public Raison_Sociale__c myRaisonSociale {get;set;}

public boolean displayPopup {get; set;}

public void closePopup() {
	displayPopup = false;
}

public void showPopup() {
	displayPopup = true;
} 

(...)

//Uploading an image in a specific Document directory
public PageReference doUpload() 
{
	if (document.body != null) {
		system.debug('body is not null');
		if (document.name != null) {
			system.debug('name is not null');
			Document d = document;
			//Looking for the Document directory named Logos Factures               
			Folder[] folders = [select id from Folder where name='Logos_Facture'];
			if (folders.isEmpty()) {
				system.debug('Did not find Logos_Factures directory');
				d.folderid = UserInfo.getUserId(); //store in Personal Documents
			} else {
				system.debug('found Logos_Factures directory');
				d.folderId = folders[0].id;
			}
			//Making the document available to everyone
			d.IsPublic = true;
			try {
				insert d;
				system.debug('insert doc ok');
				system.debug('BEFORE: template url logo = ' + myTemplate.URL_Logo__c);
				myTemplate.URL_Logo__c = DocumentUtil.getInstance().getURL(d);
				system.debug('AFTER: template url logo = ' + myTemplate.URL_Logo__c);
				update myTemplate;
				system.debug('update url logo ok');
			} catch (Exception e) {
				ApexPages.addMessages(e);
				system.debug('Problem inserting the document or updating the template: ' + e);
			}  

			d.body = null;
			
			//Adding redirection if using the pop-up module
			//so the page gets refreshed since rerender is not supported
			PageReference curPage = ApexPages.currentPage();
			curPage.setRedirect(true);
			return curPage;
		} else {
			system.debug('name is null');
		}
	} else {
		system.debug('body is null');
	}

	return null;
}

 

 

Hi All, 

 

We are trying to connect Account to a custom object Purchase Order in a One to Many Relation. A custom field called account number will be auto populated in Purchase Order from Account object. But while saving the record we are getting a "Cant update a read only record" exception.

 

Had read some more posts on this exception, but we were not clear on that.

 

The code is :

 

trigger IntegratePOtoAccount on Purchase_Order__c (after insert, after update) {

//Declare Variables
public Map<Id,Id> poAccountId = new Map<Id, Id>();
public Map<Id,String> accIDAccNumber = new Map<Id, String>();
public List<Account> accountList = new List<Account>();
public List<Purchase_Order__c> poList = new List<Purchase_Order__c>();
public Purchase_Order__c po_rec;
public Id accountId;
public String accountNumber;

 
    //Fetch the account id from Purchase Order
    for(Purchase_Order__c po : trigger.new) {
    System.debug('po is'+po.Id);
    System.debug('po is 2'+po.Account__c);
       poAccountId.put(po.Id,po.Account__c);
    }

    //Query all records of account to create a map
    accountList = [Select Id, name, account_number__c from account];

    //Put all the accounts in a map from Id to account  number
    for(Account acc : accountList) {
        accIDAccNumber.put(acc.Id, acc.account_number__c);
    }

    //Insert the Account Number for each PO
    for(Purchase_Order__c po : trigger.new) {
        accountId = poAccountId.get(po.Id);
        accountNumber = accIDAccNumber.get(accountId);
        po.oracle_account_number__c = accountNumber;
    }

}

 

Could you please let us know how to tackle this. we get an error at the last line po.oracle_account_number__c = accountNumber;

 

Thanks in Advance!

Rajat

Hi All, I wanted to retrieve Salesforce Id of a field in Apex code. Any Idea? Thanks
  • December 03, 2010
  • Like
  • 0