List of errors in visualforce page salesforce

VF :
-----

<apex:page standardController="Contact" extensions="SKT_ErrorListPage_CLS">
     <apex:form >
         <apex:pageMessages escape="false" id="messages"></apex:pageMessages>
         <apex:pageBlock title="Contact Details">
             <apex:pageBlockSection >
                 <apex:inputField value="{!con.lastname}"/>
                 <apex:inputField value="{!con.LeadSource}"/>
                 <apex:inputField value="{!con.Level__c}"/>
                 <apex:inputField value="{!con.Status__c}"/>
                 <apex:inputField value="{!con.Applcation__c}"/>
                 <apex:inputField value="{!con.Monday_Shift__c}"/>
                 <apex:inputField value="{!con.CallBackTime__c}"/>
                 <apex:inputField value="{!con.phone}"/>
             </apex:pageBlockSection>
             <apex:pageBlockButtons >
                 <apex:commandButton value="Submit" action="{!cmdSubmitButton}"/>
             </apex:pageBlockButtons>
         </apex:pageBlock>
     </apex:form>
</apex:page>

Apex:
-----

public with sharing class SKT_ErrorListPage_CLS{
    public contact con {get;set;}
    public SKT_ErrorListPage_CLS(ApexPages.StandardController controller){
        con = new contact();
    }
    public List < String > lstErrors = new List < String > ();
    public Integer errorCount = 0;
    public pagereference cmdSubmitButton(){
    try{
         lstErrors.clear();
         errorCount = 0;
         if(con.Level__c != NULL || con.Level__C != '--None--'){
             if(con.Level__c !='Primary' ){
                 errorCount = 1;
                 lstErrors.add('Level always primary only');                 
             }
         }
         if (con.Status__c == 'Call in Progress') {
             errorCount = 1;
             lstErrors.add('Please select Valid Disposition Value');
         }else if(con.Status__c == 'Call Back' || con.Status__c =='Nurture'){
             if(con.CallBackTime__c == NULL){
                errorCount = 1;
                lstErrors.add('Please provide Call Back Time');
            }else if(con.CallBackTime__c < System.Now()) {
                errorCount = 1;
                lstErrors.add('Call Back Time must be  future date/time.');
            }
         }
         if(con.phone == NULL){
             errorCount = 1;
             lstErrors.add('Please provide valid phone');
         }
         if(con.leadsource<>'SKTT'){
             errorCount = 1;
             lstErrors.add('Please provide Lead Source as SKTT');
         } 
         if (errorCount > 0){
            lstErrors.sort();
            processError(lstErrors);
            return null;
        }else{
            insert con;
            //id cuId = con.id;
            return new pagereference('/'+con.id);
        }     
    }catch(exception e){
        ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR, e.getMessage()));
        return null;
    }
    }
    public String stringError;
    public void processError(List < String > lstErrors) {
        stringError  = '<font color="red"> Input Requried for <ul style="color: red;">';
        for (String error: lstErrors) {
            stringError += '<li>' + error + '</li>';
        }
        stringError += '</ul></font>';
        ApexPages.Message myErrors = new ApexPages.Message(ApexPages.severity.Info, stringError);
        ApexPages.addMessage(myErrors);
    }
}


Screenshot:
----------------



No comments:

Featured

What is Cryptography in salesforce and what are all the algorithms provided by them ?

A). It is a security protocal between two systems. Lets say we are integration two systems without any encrytion mechanism then hackers wil...

Popular