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
Nuno REISNuno REIS 

Button controlling field values then laucn a VFP pdf

Hello all,

I need some advice, help on a business requirement.
I will create a new custom button on opportunity object.
After clicking on this button the first step is to control a few fields and validate if they are filled in.
If some fields are empty we have to display a popup (or a VFP page) including error messages about the empty fields. If all the fields are filled in the system will display a VFP rendered as a PDF page.

How can achieve that? Maybe do you have some examples?
Many thanks,
Nuno.
  
Shawn Reichner 29Shawn Reichner 29
You can try to create an onclick javescript button and use something like the followign to check for null values and then redirect to your VF page where you are rendering as a PDF.  First you will setup your variables and then check to see if they are empty/null and then display the message you would like and then redirect to your Vf page. 

If this helps you out, please mark as best answer...

Shawn

var naics = "{!Lead.NAICS_Code__c}"; 
var sltn = "{!Lead.Solution__c}"; 
var cmpny = "{!Lead.Company_Channel__c}"; 



if(naics == ''){ 
html = '<div id="dialog" style="display: none" title="Error"><p> INSERT ERROR MESSAGE HERE {!$Profile.Name} </p></div>'; 
dialogBox(html); 
}else if(sltn == ''){ 
html = '<div id="dialog" style="display: none" title="Error"><p>INSERT ERROR MESSAGE HERE </p></div>'; 
dialogBox(html); 
}else if(cmpny == ''){
html = '<div id="dialog" style="display: none" title="Error"><p> INSERT ERROR MESSAGE HERE </p></div>'; 
dialogBox(html); 
}else{
window.location = '/INSERT VF Page HERE.jsp?retURL=%2F{!Lead.Id}&id={!Lead.Id}'; 
}

function dialogBox(){
{!REQUIRESCRIPT('//ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js')} 
{!REQUIRESCRIPT('//ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.js')} 

var $g = jQuery.noConflict(); 
$g(function() { 
$g('head').append('<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">'); 
$g('body').append(html); 

$g("#dialog").dialog({
dialogClass: "no-close", 
autoOpen: true,
buttons: [
{
text: "OK",
click: function() {
$g( this ).dialog( "close" );
}
}


}); 
});
}
Nuno REISNuno REIS
Thank you for your help. In fact we use lightning UI. So you are not able to use  onclick javescript button.
Do you know another way to achieve the behaviour?
Shawn Reichner 29Shawn Reichner 29
No unfortunately, that is one of the many reasons we havenot moved to lightning as of yet.   Sorry about that, wish you the best!

Shawn