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
Salesforce Admin 78Salesforce Admin 78 

Error of validation rule on VF page is showing two times

Hi

1. I have created a validation rule on custom object.
2. I'm receiving error two times on VF page when validation rule is true and my error location is top of page.
3. I have added <apex:pagemessages /> on VF page.
4. In Apex Controller i have added apexpages.addMessages(e); in catch exception 

My Validation Rule 
AND(TEXT(ZDCP__c) <> null, ISBLANK(PCM_Sheet__r.Agent__c ))

Error is showing like this:
User-added image


Can anybody please tell how can i get the error one time.??

 
Salesforce Admin 78Salesforce Admin 78
Hi Dayakar
Thamks for your valuaable time.

But I didn't understand where you are asking me to do the changes.

I'm placing my VFpafe where i have made a change
<apex:page standardcontroller="PCM_Sheet__c" extensions="TridentViewPCM" sidebar="false">
<apex:pagemessages showDetail="false" />

i have added the above underline statement to my VF page


Here i'm placing the apex class where i have made a change
Public PageReference Save()
    {       
        Savepoint sp = Database.setSavepoint();
        try{
            List<PCM_Sheet__c>  pcmlistcheck = new List<PCM_Sheet__c>();
            List<PCM_Sheet__c> pcmsh = [Select Id,Quote__c,Final_PCM_from_SAP__c From PCM_Sheet__c where  Quote__c =: q.Id];
            for(PCM_Sheet__c pcm1 : pcmsh)
            {
                if(pcm1.Final_PCM_from_SAP__c == true)
                    pcmlistcheck.add(pcm1);
            }
            if(pcmlistcheck.size()>0)
            {
                apexpages.addMessage(new Apexpages.Message(Apexpages.SEVERITY.ERROR,'You cannot change this PCM , as a PCM for this quote has already been finalised'));
            }else{
                pcm_sheet__c pcmsheet2 = new pcm_sheet__c();
                pcmsheet2.quote__c = q.id;
                pcmsheet2.recordtypeid = rcdtypeid;
                pcmsheet2.Account__c = pcmsheet.Account__c;
                pcmsheet2.program2__c = pcmsheet.Program__c;
                pcmsheet2.INR_USD__c = pcmsheet.INR_USD__c;
                pcmsheet2.Inco_Terms__c = pcmsheet.Inco_Terms__c;
                pcmsheet2.Date_of_Enquiry__c = pcmsheet.Date_of_Enquiry__c;
                pcmsheet2.Costing_Date__c = pcmsheet.Costing_Date__c;
                pcmsheet2.Payment_Terms__c = pcmsheet.Payment_Terms__c;
                pcmsheet2.Agent__c = pcmsheet.Agent__c;
                //pcmsheet2.Ship_To__c = pcmsheet.Ship_To__c;
                insert pcmsheet2;
                pcmId = pcmsheet2.Id;
                list<pcm_lineitem__c> saveitemlist = new list<pcm_lineitem__c>();
                for(pcm_lineitem__c p : lineitemlist){
                    p.PCM_Sheet__c = pcmsheet2.id;
                    saveitemlist.add(p);
                    system.debug('helloo  '+p);
                }
                list<PCM_LineItem__c> PCM_LI_insert = new list<PCM_LineItem__c>();
                PCM_LI_insert = saveitemlist.deepClone(false);
                
                insert PCM_LI_insert;
            }
            sr=false;
        }
        catch(DMLException e)
        {
            Database.rollback(sp);  
             apexpages.addMessages(e);
        }
        
        return null;    
    }

I have added the above underlines statement to my apex code in catch exception.

Here is my Validation Rule i have made
 
AND(TEXT(ZDCP__c) <> null, ISBLANK(PCM_Sheet__r.Agent__c ))

Please tell where i have to made changes.
 
Salesforce Admin 78Salesforce Admin 78
Please help in getting the above error resolved.
Thanks in advance.