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
Calvin BarrCalvin Barr 

Show errors on blank fields when generating a PDF

Hello, 

I’m trying to create an Opportunity-controlled Visualforce page that creates a quote, but throws an error when custom opportunity fields are NULL when generating a PDF via a Button in the Opportunity layout.

The goal is to be able to keep updating opportunity fields, but only get warning messages if the fields required for a quote are left blank
I found some sample code that makes sense it, but I’m a beginner, so I’m not sure where to house the Apex Code to apply it to the VF Page
 

Visualforce Code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<apex:page standardController="Account" extensions="ErrorMessageInVfController">
 <apex:form >
   <apex:pageblock >
      <apex:pageMessages id="showmsg"></apex:pageMessages>
         <apex:panelGrid columns="2">
           Account Name: <apex:inputText value="{!acc.name}"/>
           Account Number: <apex:inputText value="{!acc.AccountNumber}"/>
           Account Phone: <apex:inputText value="{!acc.phone}"/>
           Account Site: <apex:inputText value="{!acc.site}"/>
           Account Industry: <apex:inputText value="{!acc.industry}"/>
           <apex:commandButton value="Update" action="{!save}" style="width:90px" rerender="showmsg"/>
         </apex:panelGrid>
    </apex:pageblock>
 </apex:form>
</apex:page>
Apex Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
public with sharing class ErrorMessageInVfController {
    public Account acc{get;set;}
    public ErrorMessageInVfController(ApexPages.StandardController controller) {
        acc = new Account();
    }
 
    public void save(){
      if(acc.name == '' || acc.name == null)
       ApexPages.addmessage(new ApexPages.message(ApexPages.severity.FATAL,'Please enter Account name'));
 
      if(acc.AccountNumber == '' || acc.AccountNumber == null)
       ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Please enter Account number'));
 
      if(acc.phone == '' || acc.phone == null)
       ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'Please enter Account phone'));
 
      if(acc.site == '' || acc.site == null)
       ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO,'Please enter Account site'));
 
      if(acc.industry == '' || acc.industry == null)
       ApexPages.addmessage(new ApexPages.message(ApexPages.severity.CONFIRM,'Please enter Account industry'));
 
    }
}
 
Any direction be much appreciated  :)
 
SalesFORCE_enFORCErSalesFORCE_enFORCEr
If it is Opportunity controlled then you should use the Opportunity standard controller in the vf page and modify the fields on the page accordingly. 
What do you mean by "where to house the Apex Code to apply it to the VF Page"?