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
James Roberts 32James Roberts 32 

Problem showing error in visual force table

I'm having trouble adding custom error messages into my visual force table. 

I have created the Error Controller extension and added it to my VF page, but I am still getting the standard error message, without the graphic:

Update failed. First exception on row 0 with id a1H55000006jCXLEA2; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Your pricing is already approved. To reduce the pricing by more than 10% you will need a new approval.: []
Error is in expression '{!save}' in component <apex:commandButton> in page pricingtable3years: Class.PricingTable.save: line 22, column 1

Controller:
public with sharing class ErrorMessageInVfController {
    public Opportunity_Pricing__c op{get;set;}
    public ErrorMessageInVfController(ApexPages.StandardController controller) {
        op = (Opportunity_Pricing__c)controller.getRecord();
    }
 
    public void save(){ 
      if(op.Pricing_Sheet_Approved__c = TRUE && (op.Average_MRR__c < (op.Approved_MRR__c*0.9)) )
       ApexPages.addmessage(new ApexPages.message(ApexPages.severity.FATAL,'Your pricing is already approved. To reduce the pricing by more than 10% you will need a new approval.'));
 
    }
}

Visual Force page Extract:
<apex:page standardController="Opportunity_Pricing__c" extensions="PricingTable,ErrorMessageInVfController" lightningStylesheets="true">
    <apex:slds />
    <apex:form >
       <apex:pageBlock >
        <apex:pageMessages id="showmsg"></apex:pageMessages>
           <apex:pageBlockButtons >
               <apex:commandButton value="Save" action="{!save}" oncomplete="ReloadPage();" rerender="showmsg" />
        </apex:pageBlockButtons>
           <table>
               <tr >
                   <th></th>
                   <th>Included</th>
                   <th>Year 1</th>
                   <th>Year 2</th>
                   <th>Year 3</th>
               </tr>                    
 
Alain CabonAlain Cabon
For a boolean, the test is useless and it is "==" in apex (different from a formula).

 if(op.Pricing_Sheet_Approved__c && (op.Average_MRR__c < (op.Approved_MRR__c*0.9)) )

 
James Roberts 32James Roberts 32
Thanks, but still see the basic error message with no image.