+ Start a Discussion
SFDC DummySFDC Dummy 

How to display alert message:urgent

Hi All

I have created a Vf page for trial the balance.i want to dispaly a alert message when debit and credit balance not same and now debit balance showing 0.0 format i want to display that in 0.00 format like credi balance how to chnage that for my requirment

User-added image
<apex:page docType="html-5.0" standardController="MasterCopy__c"  extensions="dateInPBTbaleControllernewOk"  showHeader="false" sidebar="false">
<apex:pageMessages id="showmsg" ></apex:pageMessages>

<style type="text/css" media="print">
@media print
{
#non-printable { display: none; }
#printable {
display: block;
width: 100%;
height: 100%;
}
}
</style>


        <apex:define name="body">
            
            <div style="width:800px;margin: 0px auto 10px auto;border: 1px solid black;">
    <apex:form id="tableId">
        <apex:pageBlock >
            
                    <b><apex:outputLabel value="Trial Balance Report On: "  style="font-weight: bold;color:red;"/></b>
                     <apex:inputField value="{!account.Date__c}" style="font-weight: bold;color:red;"/>
                     
                     
                   <!--- Trial Balance Report On: <apex:input type="date" value="{!dat}"/>-->
                 
                 <apex:commandButton value="Display" action="{!displaingTable}" reRender="tableId" style="font-weight: bold;color:red;" oncomplete="window.opener.location.refresh();" />
        <b><apex:commandLink id="printable"  onclick="JavaScript:window.print();" value="Print"/></b> <br/><br/><br/>
                 
                 <apex:pageblockTable value="{!listAccount }" var="record"  >
                
                    <apex:column value="{!record.Master_Code__c}" headerValue="Master Code"/>
                    <apex:column value="{!record.Master_Name__c}" headerValue="Master Name">
                    <apex:facet name="footer" >
                    
                    <apex:outputText value="HDFC CLOSING BALANCE: Rs.{0, number, ###,###,###,##0.00}"  style="font-weight: bold;color:green;font-size:12px;height=18px;"  >
                        <apex:param value="{!totalRevenuee}" />
                   
                     </apex:outputText>
                </apex:facet>
            </apex:column>
                    <apex:column value="{!record.New_Debit__c}" headerValue="Debit(+)" style="color:green;" >
                     <apex:facet name="footer" >
        
                    <apex:outputText value=" Rs.{!totalRevenue}<br/> Rs.{!totalRevenuee}<br/>-----------------<br/> Rs.{!totalRevenuee1}" style="font-weight: bold;color:green;font-size:12px;height=18px;" escape="false">
                      
                       
                    </apex:outputText>
                </apex:facet>
            </apex:column>
                    <apex:column value="{!record.New_Credit__c}" headerValue="Credit(-)" style="color:red;"  >
                    <apex:facet name="footer" >
                   
                        
                        
                     <apex:outputText value="Rs.{!totalRevenue1}"  style="font-weight: bold;color:red;font-size:12px;height=18px;"  >
                        
                    </apex:outputText>
                     
                </apex:facet>
                 
            </apex:column>
            
             <!---  <td  style="background-color: #DAFFFF" ><b> <apex:outputText value="Current Total" /></b></td>
           <apex:column value="{!record.Bank_Closing_Balance__c}" headerValue="Bank Closing Balance" style="color:green;">
                    <apex:facet name="footer" >
                    <apex:outputText value="Rs.{0, number, ###,###,###,##0.00}"  style="font-weight: bold;color:green;font-size:12px;height=18px;"  >
                        <apex:param value="{!totalRevenuee}"  />
                    </apex:outputText>
                </apex:facet>
            </apex:column>-->
             
           
                    </apex:pageblockTable>
                            
                    
        </apex:pageBlock>
    </apex:form>
      </div>
        </apex:define>
</apex:page>
-------------------------------------------------------------------------------------------------

public with sharing class dateInPBTbaleControllernewOk {
    public MasterCopy__c account{get;set;}
    public List<MasterCopy__c> listAccount {get;set;}
    public Double totalRevenue {get;set;}
    public Double totalRevenue1 {get;set;}
    public Double totalRevenuee {get;set;}
    public Double totalRevenuee1 {get;set;}
   
    public Date dat {get;set;}
    
    public Map<Date,List<MasterCopy__c>> mapOfDateWithEntry;

    public dateInPBTbaleControllernewOk(ApexPages.StandardController controller){
    
        account = new MasterCopy__c();
        totalRevenue = 0;
        totalRevenue1 = 0;
        totalRevenuee = 0;
        totalRevenuee1 = 0;
        
    }
     
   public void setValues(){
        listAccount  = new List<MasterCopy__c>([SELECT id,  Closing_Balance__c,Credit__c,Credit_Formula__c,Debit_Formula__c,Date__c,DateUpdate__c,Debit__c,
        Group__c,Master_Code__c,Master_Name__c,New_Debit__c,New_Credit__c
                        FROM MasterCopy__c
                        order by Master_Code__c ASC ]);
        mapOfDateWithEntry = new Map<Date,List<MasterCopy__c>>();
        List<MasterCopy__c> listOfEntryData;
        for(MasterCopy__c entry : listAccount){
            if(mapOfDateWithEntry.containsKey(entry.Date__c)){
                mapOfDateWithEntry.get(entry.Date__c).add(entry);
            }
            else{
                listOfEntryData = new List<MasterCopy__c>();
                listOfEntryData.add(entry);
                mapOfDateWithEntry.put(entry.Date__c,listOfEntryData);
            }
        }
        calculateTotalRevenue();
        calculateTotalRevenue1();
        calculateTotalRevenue2();
   }
   public void displaingTable(){
        setValues();
        if(account.Date__c != null){
            totalRevenue = 0;
            totalRevenue1 = 0;
            totalRevenuee = 0;
            totalRevenuee1 = 0;
            Set<Date> allDateSet = mapOfDateWithEntry.keySet();
            if(allDateSet.contains(account.Date__c)){
                listAccount = mapOfDateWithEntry.get(account.Date__c);
            }
            else {
                Date compareDate ;
                Integer count = 0;
                for(Date firstKeydate : allDateSet){
                    compareDate = firstKeydate;
                    break;
                }
                for(Date keyDate : allDateSet){
                    if(keydate < account.Date__c && keydate > compareDate){
                        compareDate = keyDate;
                    }
                    if(account.Date__c < keyDate){
                        count ++ ;
                    }
                }
                Date requiredDate ;
                
                if(allDateSet.size() == count){
                    requiredDate = [Select Date__c from MasterCopy__c Order by Date__c Desc LIMIT 1][0].Date__c;
                }
                else {
                    requiredDate = compareDate;
                }
                listAccount = mapOfDateWithEntry.get(requiredDate);
            }
        }
       calculateTotalRevenue();
        calculateTotalRevenue1();
        calculateTotalRevenue2(); 
    
    }
     public void calculateTotalRevenue() {
     for(MasterCopy__c acct2 : listAccount) {
            if(acct2.Closing_Balance__c!= null)
                totalRevenuee= acct2.Closing_Balance__c;
                }
        for(MasterCopy__c acct : listAccount) {
            if(acct.New_Debit__c!= null)
                totalRevenue+= acct.New_Debit__c;
                
                }
totalRevenuee1=totalRevenuee+totalRevenue;
             
       
        
    }
    
    
    
    public void calculateTotalRevenue2() {
        for(MasterCopy__c acct2 : listAccount) {
            if(acct2.Closing_Balance__c!= null)
                totalRevenuee= acct2.Closing_Balance__c;
            
              
        }
        
    }
    public void calculateTotalRevenue1() {
        for(MasterCopy__c acct1 : listAccount) {
            if(acct1.New_Credit__c!= null)
                totalRevenue1+= acct1.New_Credit__c;
                 
               
        }
        
    }
}

 
salesforce mesalesforce me
Hi u can insert this code on ur visualforce page...
ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'Error Message.');
ApexPages.addMessage(myMsg);

 
SFDC DummySFDC Dummy
how to put condition if debit balance is not equal to credit balance
Pramodh KumarPramodh Kumar
Here is the small snippet where i used javascript function to dispaly warning message.

I am reading the footer values and comparing them, if it doesnt match then i am throwning the pagemessage.  
Please let me know if you need any other help
<apex:page controller="tablePagemessage">
    <apex:includeScript value="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js" />
    <script>
    	$(document).ready(function(){
            debugger;
            var id1 =$('tfoot th:eq(0)').text();
            var id2 =$('tfoot th:eq(1)').text();
            console.log('id1'+id1+'id2'+id2);
            if(id1 != id2){
                showMessage('WARNING', 'This would be really cool indeed!');
                }
        });
    </script>
    <apex:form>
        
        <apex:actionFunction name="showMessage" action="{!showMessage}" rerender="jserror">
          <apex:param name="errorLevel" assignTo="{!errorLevel}" value="" />
          <apex:param name="messageName" assignTo="{!messageName}" value="" />
        </apex:actionFunction>
    </apex:form>
  <apex:pageBlock>
      <apex:pageMessages id="jserror"></apex:pageMessages>
     	<apex:pageBlockTable value="{!accList}" var="acc" >
            <apex:column >
                <apex:facet name="footer">
                    <apex:outputText id="accName" value="{!accname}"></apex:outputText>
                </apex:facet>
            </apex:column>
            <apex:column >
                <apex:facet name="footer">
                    <apex:outputText id="accId" value="{!accid}"></apex:outputText>
                </apex:facet>
            </apex:column>
      </apex:pageBlockTable>
      
  </apex:pageBlock>
</apex:page>


public class tablePagemessage {
    public list<account> acclist{get;set;}
    public string accName {get;set;}
    public string accId {get;set;}
    public String errorLevel {get; set;}
	public String messageName {get; set;}
    public tablePagemessage(){
        acclist = [select id,name from account limit 1];
        accname = acclist[0].id;
        accId = accList[0].name;
    }
    public void showMessage() {
        system.debug('ddddddddd');
      if(errorLevel == 'WARNING') {
        ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Warning, messageName));
      }
	}
}

Thanks,
Pramodh.