+ Start a Discussion
SFDC DummySFDC Dummy 

How to search record datewise...

Hi...
I have created a page which will search record date wise...
like i have record

date                            value
10/9/2015--------------------a
11/9/2015--------------------aa
12/9/2015--------------------aaa
14/9/2015--------------------aaaa
15/9/2015--------------------aaaaa
20/9/2015--------------------aaaaaa

if i am searching record on 10/9/2015 the record will be display  'a'
if i am searching record on 11/9/2015 the record will be display  'aa'
if i am searching record on 13/9/2015 the record will be display  'aa'(12/9/2015 record)
if i am searching record on 14/9/2015 the record will be display  'aaaa'
if i am searching record on 20/9/2015 the record will be display  'aaaaaa'
if i am searching record on 19/9/2015 the record will be display  'aaaaa'(15/9/2015 record)

if there is record on particular date it will display if there is no record on that date it will display last date record

 
public with sharing class dateInPBTbaleController {

    public dateInPBTbaleController() {

    }


    public dateInPBTbaleController(ApexPages.StandardController controller) 
    {
    
     account = new BankBook_Entry__c();
         totalRevenue = 0;
        totalRevenue1 = 0;
        totalRevenuee = 0;
        
    

    }

    public BankBook_Entry__c account{get;set;}
    public List<BankBook_Entry__c> listAccount {get;set;}
   
    public Date startDate1;
    public Date endDat1;
    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 dateInPBTbaleController() {
       
       
     public void displaingTable(){
        startDate1 = account.Date__c; 
        endDat1 = account.Date__c;
        if(endDat1!=null){
 
 
        listAccount  = [SELECT id, CB__c,Date__c,Debit__c,Master_Code1__c,Master_Name__c,Bank_Closing_Balance__c
                          FROM BankBook_Entry__c
                        WHERE Date__c>=:startDate1 AND Date__c<=:endDat1 order by Master_Code1__c ASC ];
                        }//Date__c>=:startDate1 AND
       
       calculateTotalRevenue();
        calculateTotalRevenue1();
        calculateTotalRevenue2();
     }
     public void calculateTotalRevenue() {
        for(BankBook_Entry__c acct : listAccount) {
            if(acct.Debit__c!= null)
                totalRevenue+= acct.Debit__c;

              
        }
        
    }
    
    
    
    public void calculateTotalRevenue2() {
        for(BankBook_Entry__c acct2 : listAccount) {
            if(acct2.Bank_Closing_Balance__c!= null)
                totalRevenuee= acct2.Bank_Closing_Balance__c;
            // totalRevenuee+= acct.Bank_Closing_Balance__c+totalRevenue;
              
        }
        
    }
    public void calculateTotalRevenue1() {
        for(BankBook_Entry__c acct1 : listAccount) {
            if(acct1.CB__c!= null)
                totalRevenue1+= acct1.CB__c;
               
        }
        
    }
}
----------------------------------------------------------------------

<apex:page docType="html-5.0" standardController="BankBook_Entry__c"  extensions="dateInPBTbaleController">


        <apex:define name="body">
            
            <div style="width:800px;margin: 0px auto 10px auto;border: 1px solid black;">
    <apex:form >
        <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;"/><br/><br/><br/>
         
                 <apex:pageblockTable value="{!listAccount }" var="record" id="tableId" >
                    <apex:column value="{!record.Master_Code1__c}" headerValue="Master Code"/>
                    <apex:column value="{!record.Master_Name__c}" headerValue="Master Name"/>
                    <apex:column value="{!record.Debit__c}" headerValue="Debit(+)" style="color:green;" id="tableId">
                     <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="{!totalRevenue}"  />
                    </apex:outputText>
                </apex:facet>
            </apex:column>
                    <apex:column value="{!record.CB__c}" headerValue="Credit(-)" style="color:red;">
                    <apex:facet name="footer" >
                    <apex:outputText value="Rs.{0, number, ###,###,###,##0.00}"  style="font-weight: bold;color:red;font-size:12px;height=18px;"  >
                        <apex:param value="{!totalRevenue1}"  />
                    </apex:outputText>
                </apex:facet>
            </apex:column>
            
             <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:red;font-size:12px;height=18px;"  >
                        <apex:param value="{!totalRevenue1}"  />
                    </apex:outputText>
                </apex:facet>
            </apex:column>
                    
                    
                    </apex:pageblockTable>
             
        </apex:pageBlock>
    </apex:form>
      </div>
        </apex:define>
</apex:page>

 
Best Answer chosen by SFDC Dummy
Abhishek BansalAbhishek Bansal
Change Code :
 
trigger UpsertMasterNew on Debtors_Ledger__c(after insert,after update) {
	List<Debtors_Ledger__c> allDebtor = new List<Debtors_Ledger__c>([Select DailyUpdate__c,Name,Debtor_Name__c from Debtors_Ledger__c]);
	List<MasterCopy__c> allMasterData = new List<MasterCopy__c>([Select Name,Date__c,Master_Code__c,Master_Name__c,Credit__c,Debit__c from MasterCopy__c]);
	Map<String,MasterCopy__c> mapOfMasterWithName = new Map<String,MasterCopy__c>();
	Set<Date> dateSet = new Set<Date>();
	for(MasterCopy__c master : allMasterData){
		mapOfMasterWithName.put(master.Master_Code__c,master);
		dateSet.add(master.Date__c);
	}
	
	List<MasterCopy__c> insertList = new List<MasterCopy__c>();
	MasterCopy__c masterRec;
	Date updatedate = trigger.new[0].DailyUpdate__c;
	if(allMasterData.size() == 0){
		for(Debtors_Ledger__c debtor : allDebtor){
			masterRec = new MasterCopy__c();
			masterRec.Master_Code__c= debtor.Name;
			masterRec.Date__c = updatedate;
			masterRec.Master_Name__c= debtor.Debtor_Name__c;
			masterRec.Credit__c= debtor.Credit_formula__c;
			masterRec.Debit__c= debtor.Debit_formula__c;
			insertList.add(masterRec);
		}
	}
	else{
		if(dateSet.contains(updatedate)){
			mapOfMasterWithName.get(trigger.new[0].Name).Credit__c = trigger.new[0].Credit_formula__c;
			mapOfMasterWithName.get(trigger.new[0].Name).Debit__c = trigger.new[0].Debit_formula__c;
		}
		else{
			for(Debtors_Ledger__c debtor : allDebtor){
				masterRec = new MasterCopy__c();
				masterRec.Master_Code__c= debtor.Name;
				masterRec.Date__c = updatedate;
				masterRec.Master_Name__c= debtor.Debtor_Name__c;
				masterRec.Credit__c= debtor.Credit_formula__c;
				masterRec.Debit__c= debtor.Debit_formula__c;
				insertList.add(masterRec);
			}
		}
	}
	insertList.addAll(mapOfMasterWithName.values());
	upsert insertList;
}

 

All Answers

Abhishek BansalAbhishek Bansal
Hi,

Please add below mention code in your Vf page and Controller class :

VF Page code :

<apex:inputField value="{searchDateField}"/>
<apex:commandButton value="Search" action="{!search} rerender="datePanel"/>"

<apex:outputPanel id="datePanel" rendered="{!If(resultantDate != null, true,false)}">
<apex:outputLabel value="Resultant Date :"/>
<apex:outputField value="{!resultantDate}"/>
</apex:outputPanel>


Class Code :

public Date searchDateField {get;set;}
public Date resultantDate {get;set;}

public void Search(){
    List<BankBook_Entry__c> acc = new List<BankBook_Entry__c>();
    acc = [Select Date__c from BankBook_Entry__c where Date__c = :searchDateField LIMIT 1];

    if(acc.size() == 0) {
        acc = [Select Date__c from BankBook_Entry__c where Date__c < :searchDateField LIMIT 1];
    }
    
    if(acc.size() == 0) {
        acc = [Select Date__c from BankBook_Entry__c Order By Date__c DESC LIMIT 1];
    }
    
    resultantDate = acc[0].Date__c;
}


Plesae let me know if you need any help regarding this.

Thanks,
Abhishek
Abhishek BansalAbhishek Bansal
Hi,

I have modified your controller class according to your requirement.
Please ignore the previous post and update your class code as follows :

public with sharing class dateInPBTbaleController {
    public BankBook_Entry__c account{get;set;}
    public List<BankBook_Entry__c> listAccount {get;set;}
   
    //public Date startDate1;
    //public Date endDat1;
    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 dateInPBTbaleController() {
        listAccount  = [SELECT id, CB__c,Date__c,Debit__c,Master_Code1__c,Master_Name__c,Bank_Closing_Balance__c
                        FROM BankBook_Entry__c
                        order by Master_Code1__c ASC ];
    }

    public dateInPBTbaleController(ApexPages.StandardController controller){
    
        account = new BankBook_Entry__c();
        totalRevenue = 0;
        totalRevenue1 = 0;
        totalRevenuee = 0;
    }
       
    public void displaingTable(){
        if(account.Date__c != null){
            listAccount  = [SELECT id, CB__c,Date__c,Debit__c,Master_Code1__c,Master_Name__c,Bank_Closing_Balance__c
                                FROM BankBook_Entry__c
                                WHERE Date__c =: account.Date__c order by Master_Code1__c ASC ];
            
            if(listAccount.size() == 0){
                listAccount  = [SELECT id, CB__c,Date__c,Debit__c,Master_Code1__c,Master_Name__c,Bank_Closing_Balance__c
                                FROM BankBook_Entry__c
                                WHERE Date__c <: account.Date__c order by Master_Code1__c ASC ];
            }
            
            if(listAccount.size() == 0){
                listAccount  = [SELECT id, CB__c,Date__c,Debit__c,Master_Code1__c,Master_Name__c,Bank_Closing_Balance__c
                                FROM BankBook_Entry__c
                                order by Date__c DESC LIMIT 1 ];
            }
        }
        
       
        calculateTotalRevenue();
        calculateTotalRevenue1();
        calculateTotalRevenue2();
     }
     public void calculateTotalRevenue() {
        for(BankBook_Entry__c acct : listAccount) {
            if(acct.Debit__c!= null)
                totalRevenue+= acct.Debit__c;

              
        }
        
    }
    
    
    
    public void calculateTotalRevenue2() {
        for(BankBook_Entry__c acct2 : listAccount) {
            if(acct2.Bank_Closing_Balance__c!= null)
                totalRevenuee= acct2.Bank_Closing_Balance__c;
            // totalRevenuee+= acct.Bank_Closing_Balance__c+totalRevenue;
              
        }
        
    }
    public void calculateTotalRevenue1() {
        for(BankBook_Entry__c acct1 : listAccount) {
            if(acct1.CB__c!= null)
                totalRevenue1+= acct1.CB__c;
               
        }
        
    }
}


Let me know if there is any issue.

Regards,
Abhishek.
SFDC DummySFDC Dummy
Abhishek i have tried this controller but its showing all previous date value like 1/1/2005==aa 2/1/2005==aaa 4/1/2005==aaaa 10/1/2005==aaaaa if i am seraching record on 11/1/2005 it will display only the previous date record means 10/1/2005 record.but as of modified code it will display all date record....
Abhishek BansalAbhishek Bansal
Hi,

Please modify this method code :


public void displaingTable(){
        if(account.Date__c != null){
            listAccount  = [SELECT id, CB__c,Date__c,Debit__c,Master_Code1__c,Master_Name__c,Bank_Closing_Balance__c
                                FROM BankBook_Entry__c
                                WHERE Date__c =: account.Date__c order by Master_Code1__c ASC ];
            
            if(listAccount.size() == 0){
                listAccount  = [SELECT id, CB__c,Date__c,Debit__c,Master_Code1__c,Master_Name__c,Bank_Closing_Balance__c
                                FROM BankBook_Entry__c
                                WHERE Date__c <: account.Date__c order by Master_Code1__c ASC LIMIT 1 ];
            }
            
            if(listAccount.size() == 0){
                listAccount  = [SELECT id, CB__c,Date__c,Debit__c,Master_Code1__c,Master_Name__c,Bank_Closing_Balance__c
                                FROM BankBook_Entry__c
                                order by Date__c DESC LIMIT 1 ];
            }
        }

Regards,
Abhishek
SFDC DummySFDC Dummy
Hi Abhishek

 I have tried above modified code but it will dispaly only one record..i have 10/1/2001 record if i am searching 10/1/2001 it will dispaly like this
User-added image
As per my requirment there is  no record in 11/1/2001....If i am searching on that day it will be display last day record ,means 10/1/2001 record only.but it will dispaly
User-added image
public with sharing class dateInPBTbaleController {
    public BankBook_Entry__c account{get;set;}
    public List<BankBook_Entry__c> listAccount {get;set;}
   
    //public Date startDate1;
    //public Date endDat1;
    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 dateInPBTbaleController() {
        listAccount  = [SELECT id, CB__c,Date__c,Debit__c,Master_Code1__c,Master_Name__c,Bank_Closing_Balance__c
                        FROM BankBook_Entry__c
                        order by Master_Code1__c ASC ];
    }

    public dateInPBTbaleController(ApexPages.StandardController controller){
    
        account = new BankBook_Entry__c();
        totalRevenue = 0;
        totalRevenue1 = 0;
        totalRevenuee = 0;
        totalRevenuee1 = 0;
    }
       
   public void displaingTable(){
        if(account.Date__c != null){
            listAccount  = [SELECT id, CB__c,Date__c,Debit__c,Master_Code1__c,Master_Name__c,Bank_Closing_Balance__c
                                FROM BankBook_Entry__c
                                WHERE Date__c =: account.Date__c order by Master_Code1__c ASC ];
            
            if(listAccount.size() == 0){
                listAccount  = [SELECT id, CB__c,Date__c,Debit__c,Master_Code1__c,Master_Name__c,Bank_Closing_Balance__c
                                FROM BankBook_Entry__c
                                WHERE Date__c <: account.Date__c order by Master_Code1__c ASC LIMIT 1 ];
            }
            
            if(listAccount.size() == 0){
                listAccount  = [SELECT id, CB__c,Date__c,Debit__c,Master_Code1__c,Master_Name__c,Bank_Closing_Balance__c
                                FROM BankBook_Entry__c
                                order by Date__c DESC LIMIT 1 ];
            }
        }
       
        calculateTotalRevenue();
        calculateTotalRevenue1();
        calculateTotalRevenue2();
     }
     public void calculateTotalRevenue() {
     for(BankBook_Entry__c acct2 : listAccount) {
            if(acct2.Bank_Closing_Balance__c!= null)
                totalRevenuee= acct2.Bank_Closing_Balance__c;
                }
        for(BankBook_Entry__c acct : listAccount) {
            if(acct.Debit__c!= null)
                totalRevenue+= acct.Debit__c;
                }
totalRevenuee1=totalRevenuee+totalRevenue;
              
       
        
    }
    
    
    
    public void calculateTotalRevenue2() {
        for(BankBook_Entry__c acct2 : listAccount) {
            if(acct2.Bank_Closing_Balance__c!= null)
                totalRevenuee= acct2.Bank_Closing_Balance__c;
            
              
        }
        
    }
    public void calculateTotalRevenue1() {
        for(BankBook_Entry__c acct1 : listAccount) {
            if(acct1.CB__c!= null)
                totalRevenue1+= acct1.CB__c;
               
        }
        
    }
}

-----------------------------------

<apex:page docType="html-5.0" standardController="BankBook_Entry__c"  extensions="dateInPBTbaleController">


        <apex:define name="body">
            
            <div style="width:800px;margin: 0px auto 10px auto;border: 1px solid black;">
    <apex:form >
        <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;"/><br/><br/><br/>
         
                 <apex:pageblockTable value="{!listAccount }" var="record" id="tableId" >
                    <apex:column value="{!record.Master_Code1__c}" headerValue="Master Code"/>
                    <apex:column value="{!record.Master_Name__c}" headerValue="Master Name"/>
                    <apex:column value="{!record.Debit__c}" headerValue="Debit(+)" style="color:green;" id="tableId">
                     <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="{!totalRevenuee1}"  />
                    </apex:outputText>
                </apex:facet>
            </apex:column>
                    <apex:column value="{!record.CB__c}" headerValue="Credit(-)" style="color:red;">
                    <apex:facet name="footer" >
                    <apex:outputText value="Rs.{0, number, ###,###,###,##0.00}"  style="font-weight: bold;color:red;font-size:12px;height=18px;"  >
                        <apex:param value="{!totalRevenue1}"  />
                    </apex:outputText>
                </apex:facet>
            </apex:column>
            
             <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>


 
Abhishek BansalAbhishek Bansal
Hi ,

In order to achieve your requirement i have modified your code :
Please fin below the updated code :
 
public with sharing class dateInPBTbaleController {
    public BankBook_Entry__c account{get;set;}
    public List<BankBook_Entry__c> listAccount {get;set;}
    public Map<Date,List<BankBook_Entry__c>> mapOfDateWithEntry = new Map<Date,BankBook_Entry__c>();
    //public Date startDate1;
    //public Date endDat1;
    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 dateInPBTbaleController() {
        listAccount  = [SELECT id, CB__c,Date__c,Debit__c,Master_Code1__c,Master_Name__c,Bank_Closing_Balance__c
                        FROM BankBook_Entry__c
                        order by Master_Code1__c ASC ];
		
		List<listOfEntryData> listOfEntryData;
		for(BankBook_Entry__c entry : allDataList){
			if(mapOfDateWithEntry.containsKey(entry.Date__c)){
				mapOfDateWithEntry.get(entry.Date__c).add(entry);
			}
			else{
				listOfEntryData = new List<BankBook_Entry__c>();
				listOfEntryData.add(entry);
				mapOfDateWithEntry..put(entry.Date__c,listOfEntryData);
			}
		}
    }

    public dateInPBTbaleController(ApexPages.StandardController controller){
    
        account = new BankBook_Entry__c();
        totalRevenue = 0;
        totalRevenue1 = 0;
        totalRevenuee = 0;
        totalRevenuee1 = 0;
    }
       
   public void displaingTable(){
        if(account.Date__c != null){
            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 BankBook_Entry__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(BankBook_Entry__c acct2 : listAccount) {
            if(acct2.Bank_Closing_Balance__c!= null)
                totalRevenuee= acct2.Bank_Closing_Balance__c;
                }
        for(BankBook_Entry__c acct : listAccount) {
            if(acct.Debit__c!= null)
                totalRevenue+= acct.Debit__c;
                }
totalRevenuee1=totalRevenuee+totalRevenue;
              
       
        
    }
    
    
    
    public void calculateTotalRevenue2() {
        for(BankBook_Entry__c acct2 : listAccount) {
            if(acct2.Bank_Closing_Balance__c!= null)
                totalRevenuee= acct2.Bank_Closing_Balance__c;
            
              
        }
        
    }
    public void calculateTotalRevenue1() {
        for(BankBook_Entry__c acct1 : listAccount) {
            if(acct1.CB__c!= null)
                totalRevenue1+= acct1.CB__c;
               
        }
        
    }
}
Please let me know if any issue is there.

Regards,
Abhishek
 
SFDC DummySFDC Dummy
Abhishek It showing error like [image: Error]Error: dateInPBTbaleController Compile Error: Invalid type: listOfEntryData at line 17 column 14
Abhishek BansalAbhishek Bansal
Replace that line with below line :

List<BankBook_Entry__c> listOfEntryData;
SFDC DummySFDC Dummy
Again Showing error

[Error] Error: dateInPBTbaleController Compile Error: Variable does not exist: allDataList at line 18 column 39
Abhishek BansalAbhishek Bansal
Replace allDataList with listAccount in that line.
SFDC DummySFDC Dummy
[image: Error]Error: dateInPBTbaleController Compile Error: Illegal assignment from Map to Map> at line 4 column 46
Abhishek BansalAbhishek Bansal
Change it to:
public Map<Date,List<BankBook_Entry__c>> mapOfDateWithEntry = new Map<Date,List<BankBook_Entry__c>>();
Abhishek BansalAbhishek Bansal
I saw this same question on your other post.
Are you facing any issue with the code provided by me.
If Yes, please let me know the issue, I will definitely try to help you out.
Abhishek BansalAbhishek Bansal
I saw this same question on your other post.
Are you facing any issue with the code provided by me.
If Yes, please let me know the issue, I will definitely try to help you out.
SFDC DummySFDC Dummy
Yes Abhishek I need only last day record not all record from beginning If there is no record on which date I am searching it will display previous date record. I have 1/2/2001 record I don't have 2/2/2001 ,3/2/2001,4/2/2001 record if I am searching any of this day record it will display only 1/2/2001 record If I I have record on 10/2/2001,11/2/2001,13/2/2001 and no record on 14/2/2001 and if I am searching record on 14/2/2001 it will display 13/2/2001 record.how to solve this.
Abhishek BansalAbhishek Bansal
Hi,

I have provided you the code regarding your requirement.
Please change your controller class with below code :
 
public with sharing class dateInPBTbaleController {
    public BankBook_Entry__c account{get;set;}
    public List<BankBook_Entry__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<BankBook_Entry__c>> mapOfDateWithEntry = new Map<Date,List<BankBook_Entry__c>>();
    
    public dateInPBTbaleController() {
        listAccount  = [SELECT id, CB__c,Date__c,Debit__c,Master_Code1__c,Master_Name__c,Bank_Closing_Balance__c
                        FROM BankBook_Entry__c
                        order by Master_Code1__c ASC ];
		
		List<BankBook_Entry__c> listOfEntryData;
		for(BankBook_Entry__c entry : listAccount){
			if(mapOfDateWithEntry.containsKey(entry.Date__c)){
				mapOfDateWithEntry.get(entry.Date__c).add(entry);
			}
			else{
				listOfEntryData = new List<BankBook_Entry__c>();
				listOfEntryData.add(entry);
				mapOfDateWithEntry..put(entry.Date__c,listOfEntryData);
			}
		}
    }

    public dateInPBTbaleController(ApexPages.StandardController controller){
    
        account = new BankBook_Entry__c();
        totalRevenue = 0;
        totalRevenue1 = 0;
        totalRevenuee = 0;
        totalRevenuee1 = 0;
    }
       
   public void displaingTable(){
        if(account.Date__c != null){
            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 BankBook_Entry__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(BankBook_Entry__c acct2 : listAccount) {
            if(acct2.Bank_Closing_Balance__c!= null)
                totalRevenuee= acct2.Bank_Closing_Balance__c;
                }
        for(BankBook_Entry__c acct : listAccount) {
            if(acct.Debit__c!= null)
                totalRevenue+= acct.Debit__c;
                }
totalRevenuee1=totalRevenuee+totalRevenue;
              
       
        
    }
    
    
    
    public void calculateTotalRevenue2() {
        for(BankBook_Entry__c acct2 : listAccount) {
            if(acct2.Bank_Closing_Balance__c!= null)
                totalRevenuee= acct2.Bank_Closing_Balance__c;
            
              
        }
        
    }
    public void calculateTotalRevenue1() {
        for(BankBook_Entry__c acct1 : listAccount) {
            if(acct1.CB__c!= null)
                totalRevenue1+= acct1.CB__c;
               
        }
        
    }
}

Please execute the above code and let me know if you have any issue.
If this code does not work than please let me know which cases are working and which are not working.
I will modify the code accordingly.

Regards,
Abhishek
SFDC DummySFDC Dummy
Abhishek its showing error [image: Error]Error: dateInPBTbaleController Compile Error: expecting a semi-colon, found '}' at line 58 column 20
SFDC DummySFDC Dummy
afte modification on count++ to Count++; its showing error [image: Error]Error: dateInPBTbaleController Compile Error: Initial term of field expression must be a concrete SObject: Map> at line 25 column 17
Abhishek BansalAbhishek Bansal
There are two dots in line no. 25 as Map..put.
Please remove one dot.
Change mapOfDateWithEntry..put(entry.Date__c,listOfEntryData); To mapOfDateWithEntry.put(entry.Date__c,listOfEntryData);
 
SFDC DummySFDC Dummy
it saved successfully .but when i am searching reocrd it will display VF page error Visualforce Error Help for this Page System.NullPointerException: Attempt to de-reference a null object Error is in expression '{!displaingTable}' in component in page newtrial: Class.dateInPBTbaleControllernew.calculateTotalRevenue: line 81, column 1 Class.dateInPBTbaleControllernew.displaingTable: line 76, column 1 Class.dateInPBTbaleControllernew.calculateTotalRevenue: line 81, column 1 Class.dateInPBTbaleControllernew.displaingTable: line 76, column 1
Abhishek BansalAbhishek Bansal
I dont see any error in the code.
I think you have updated the code.
Please send me the code of controller class.
SFDC DummySFDC Dummy
there is no error in code ,its saved successfully.but when i am going to search any date record its showing vf page error

Visualforce ErrorHelp for this Page
System.NullPointerException: Attempt to de-reference a null object
Error is in expression '{!displaingTable}' in component <apex:commandButton> in page newtrial1: Class.dateInPBTbaleControllernew1.calculateTotalRevenue: line 82, column 1
Class.dateInPBTbaleControllernew1.displaingTable: line 75, column 1
Class.dateInPBTbaleControllernew1.calculateTotalRevenue: line 82, column 1
Class.dateInPBTbaleControllernew1.displaingTable: line 75, column 1

 
public with sharing class dateInPBTbaleControllernew1 {
    public BankBook_Entry__c account{get;set;}
    public List<BankBook_Entry__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<BankBook_Entry__c>> mapOfDateWithEntry = new Map<Date,List<BankBook_Entry__c>>();
    
    public dateInPBTbaleControllernew1() {
        listAccount  = [SELECT id, CB__c,Date__c,Debit__c,Master_Code1__c,Master_Name__c,Bank_Closing_Balance__c
                        FROM BankBook_Entry__c
                        order by Master_Code1__c ASC ];
        
        List<BankBook_Entry__c> listOfEntryData;
        for(BankBook_Entry__c entry : listAccount){
            if(mapOfDateWithEntry.containsKey(entry.Date__c)){
                mapOfDateWithEntry.get(entry.Date__c).add(entry);
            }
            else{
                listOfEntryData = new List<BankBook_Entry__c>();
                listOfEntryData.add(entry);
                mapOfDateWithEntry.put(entry.Date__c,listOfEntryData);
            }
        }
    }

    public dateInPBTbaleControllernew1(ApexPages.StandardController controller){
    
        account = new BankBook_Entry__c();
        totalRevenue = 0;
        totalRevenue1 = 0;
        totalRevenuee = 0;
        totalRevenuee1 = 0;
        
        
       
    }
       
   public void displaingTable(){
        if(account.Date__c != null){
            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 BankBook_Entry__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(BankBook_Entry__c acct2 : listAccount) {
            if(acct2.Bank_Closing_Balance__c!= null)
                totalRevenuee= acct2.Bank_Closing_Balance__c;
                }
        for(BankBook_Entry__c acct : listAccount) {
            if(acct.Debit__c!= null)
                totalRevenue+= acct.Debit__c;
                
                }
totalRevenuee1=totalRevenuee+totalRevenue;
              
       
        
    }
    
    
    
    public void calculateTotalRevenue2() {
        for(BankBook_Entry__c acct2 : listAccount) {
            if(acct2.Bank_Closing_Balance__c!= null)
                totalRevenuee= acct2.Bank_Closing_Balance__c;
            
              
        }
        
    }
    public void calculateTotalRevenue1() {
        for(BankBook_Entry__c acct1 : listAccount) {
            if(acct1.CB__c!= null)
                totalRevenue1+= acct1.CB__c;
                 
               
        }
        
    }
}
---------------------------------

<apex:page docType="html-5.0" standardController="BankBook_Entry__c"  extensions="dateInPBTbaleControllernew1" >

<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 >
        <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"  id="tableId">
                
                    <apex:column value="{!record.Master_Code1__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.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.CB__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>

 
Abhishek BansalAbhishek Bansal
Replace line no. 14 in controller class with below line :

listAccount  = new List<>([SELECT id, CB__c,Date__c,Debit__c,Master_Code1__c,Master_Name__c,Bank_Closing_Balance__c
                        FROM BankBook_Entry__c
                        order by Master_Code1__c ASC ]);


Please let me know if any issue is still there.
SFDC DummySFDC Dummy
Again error [image: Error]Error: dateInPBTbaleControllernew1 Compile Error: expecting a left angle bracket, found '
Abhishek BansalAbhishek Bansal
Change to this :

listAccount  = new List<BankBook_Entry__c>([SELECT id, CB__c,Date__c,Debit__c,Master_Code1__c,Master_Name__c,Bank_Closing_Balance__c
                        FROM BankBook_Entry__c
                        order by Master_Code1__c ASC ]);

Let me know if you still face any issue.
SFDC DummySFDC Dummy
After modification of code in line 14 *listAccount = new List([SELECT id, CB__c,Date__c,Debit__c,Master_Code1__c,Master_Name__c,Bank_Closing_Balance__c FROM BankBook_Entry__c order by Master_Code1__c ASC ]);* *it saved succes.* *but at the time of seaching record it will display error like * Visualforce Error Help for this Page System.NullPointerException: Attempt to de-reference a null object Error is in expression '{!displaingTable}' in component in page newtrial1: Class.dateInPBTbaleControllernew1.calculateTotalRevenue: line 84, column 1 Class.dateInPBTbaleControllernew1.displaingTable: line 77, column 1 Class.dateInPBTbaleControllernew1.calculateTotalRevenue: line 84, column 1 Class.dateInPBTbaleControllernew1.displaingTable: line 77, column 1
Abhishek BansalAbhishek Bansal
Hi,

Not able to find the root cause of this error.
If possible, Please share credential of your org so that i can look into it.

Regards,
Abhishek.
SFDC DummySFDC Dummy
ok demouser@demo.com.mgsandbox server@54321
Abhishek BansalAbhishek Bansal
Please send me the verification code and the steps to open the VF page so that i can investigate the issue.
SFDC DummySFDC Dummy
15592
Abhishek BansalAbhishek Bansal
Please have a look at it now and let me know if you have any isue.
SFDC DummySFDC Dummy
its ok ...but it showing all date record intially and when search record on particaular date it will dispaly that date record its working fine .but i need intially null
Abhishek BansalAbhishek Bansal
Check now and let me know if u need any modification
SFDC DummySFDC Dummy
but calculation value taking all value addition.i need only debit or credit value addition only that day.and param value not refresh in vf page
SFDC DummySFDC Dummy
when i am searching 1/1/2001 record it will display right record but in facet it calculate all the date record value like Rs.397000.0. but this is 29000.00
Abhishek BansalAbhishek Bansal
Did not get your point
can u explain it again ?
SFDC DummySFDC Dummy
for example i am searching record on 1/1/2001 and it will display 1/1/2001 reocrd.but problem is it calculate all date value record not the particualr date value record..

see the screenshot
User-added image
SFDC DummySFDC Dummy
This will be calculate only that day record....
Abhishek BansalAbhishek Bansal
Please check it now
SFDC DummySFDC Dummy
Working Properly Now.. if i am searching 1/1/2001 record and it will display correct data and if i am overwrite the date 1/1/2001 to 2/1/2001 it will display double value .if i am refreshing and search it will display correct data.if i am overwrite the date then not working
Abhishek BansalAbhishek Bansal
It is working fine now.
Please check and mark your both answer as SOLVED in order to avoid confusion.
SFDC DummySFDC Dummy
Thanks Abhishek Its working fine Now....
Abhishek BansalAbhishek Bansal
Please close your all question related to this topic so that it can avoid confusion to others.

Thanks,
Abhishek.
SFDC DummySFDC Dummy
Abhishek I am facing one issue few days ago but  not able to fix it..

I have two custom object debtor and mastercopy.

In debtors object i have 10 record .when i am updating any record of debtors it will be created all 10 record in matsercopy automatically.if i am inserting any record on debtors it will be created all record i mean past 10 record and new inserted record in masetr copy..
if i am upadting any record with change of date it will created all record in mastercopy.

for exmplae

debtors object

1------a-----10000-------1/1/2001
2------aa-----20000-------2/1/2001
3------aaa-----20000-------3/1/2001
4------aaaa-----30000-------4/1/2001
5------aaaaa-----60000-------5/1/2001

mastercopy record
initially blank

when i am upadting one record like 1----- a-----10000-------1/1/2001 to  1------a-----90000-------10/1/2001 after saving the record in debtors it will be automatically created all record in mastercopy object  with updated date in all record like

mastercopy object after update debtors object..

1------a-----90000-------10/1/2001
2------aa-----20000-------10/1/2001
3------aaa-----20000-------10/1/2001
4------aaaa-----30000-------10/1/2001
5------aaaaa-----60000-------10/1/2001

if i am updating any record with same date in debtors object like 2------aa-----20000-------10/1/2001  to  2------aa-----240000-------10/1/2001  it will update the mastercopy record..

1------a-----90000-------10/1/2001
2------aa-----240000-------10/1/2001
3------aaa-----20000-------10/1/2001
4------aaaa-----30000-------10/1/2001
5------aaaaa-----60000-------10/1/2001

if date same it will be update the record if date change it will be create the all record .so that i can keep what the excat value of all record in particular date..


if i am upadting any record in debtors with diffrent date like 1------a-----200000-------10/1/2001 to 1------a-----200000-------11/1/2001
it will be create all record of debtors in mastercopy object.

like
1------a-----20
trigger UpsertMasterNew on Debtors_Ledger__c(after insert,after update) {
    
    if(Utility.runLedgerTrigger == true){
        
        List<Debtors_Ledger__c> allDebtor = new List<Debtors_Ledger__c>([Select DailyUpdate__c,Name,Debtor_Name__c from Debtors_Ledger__c where Id Not In : trigger.new]);
        
        Set<Date> dateSet = new Set<Date>();
        for(Debtors_Ledger__c debtor : trigger.new)
        {
            dateSet.add(debtor.DailyUpdate__c);
            for(Debtors_Ledger__c existingDebtor : allDebtor) {
                existingDebtor.DailyUpdate__c = debtor.DailyUpdate__c;
               
                
                //Add your remeiang field here
            }
        }
        
        List<MasterCopy__c> allMasterData = new List<MasterCopy__c>([Select Name,Date__c,Master_Code__c,Master_Name__c,Credit__c,Debit__c from MasterCopy__c where Date__c IN : dateSet]);
        
        Map<Date,MasterCopy__c> masterDataMap = new Map<Date,MasterCopy__c>();
        
        for(MasterCopy__c masData : allMasterData){
            masterDataMap.put(masData.Date__c,masData);
        }
        List<MasterCopy__c> insertMasterList = new List<MasterCopy__c>();
        MasterCopy__c master;
        for(Debtors_Ledger__c debtor : trigger.new){
            if(masterDataMap.containsKey(debtor.DailyUpdate__c)){
                masterDataMap.get(debtor.DailyUpdate__c).Master_Code__c= debtor.Name;   // masterDataMap.get(debtor.DailyUpdate__c).Name + ' ' +
                masterDataMap.get(debtor.DailyUpdate__c).Credit__c=  debtor.Credit_formula__c;
                masterDataMap.get(debtor.DailyUpdate__c).Debit__c=  debtor.Debit_formula__c;
            }
            else{
                master = new MasterCopy__c();
                master.Master_Code__c= debtor.Name;
                master.Date__c = debtor.DailyUpdate__c;
                
                master.Master_Name__c= debtor.Debtor_Name__c;
                master.Credit__c= debtor.Credit_formula__c;
                 master.Debit__c= debtor.Debit_formula__c;
                insertMasterList.add(master);
            }
        }
        insertMasterList.addAll(masterDataMap.values());
        if(allDebtor.size() > 0){
            Utility.runLedgerTrigger =false;
            update allDebtor;
        }
        upsert insertMasterList;
    }
}

0000-------11/1/2001
2------aa-----240000-------11/1/2001
3------aaa-----20000-------11/1/2001
4------aaaa-----30000-------11/1/2001
5------aaaaa-----60000-------11/1/2001



 
Abhishek BansalAbhishek Bansal
Hi,

Please find the code below :
trigger UpsertMasterNew on Debtors_Ledger__c(after insert,after update) {
	List<Debtors_Ledger__c> allDebtor = new List<Debtors_Ledger__c>([Select DailyUpdate__c,Name,Debtor_Name__c from Debtors_Ledger__c where Id Not In : trigger.new]);
	List<MasterCopy__c> allMasterData = new List<MasterCopy__c>([Select Name,Date__c,Master_Code__c,Master_Name__c,Credit__c,Debit__c from MasterCopy__c]);
	Map<String,MasterCopy__c> mapOfMasterWithName = new Map<String,MasterCopy__c>();
	Set<Date> dateSet = new Set<Date>();
	for(MasterCopy__c master : allMasterData){
		mapOfMasterWithName.put(master.Master_Code__c,master);
		dateSet.add(master.Date__c);
	}
	
	List<MasterCopy__c> insertList = new List<MasterCopy__c>();
	MasterCopy__c masterRec;
	Date updatedate = trigger.new[0].DailyUpdate__c;
	if(allMasterData.size() == 0){
		for(Debtors_Ledger__c debtor : allDebtor){
			masterRec = new MasterCopy__c();
			masterRec.Master_Code__c= debtor.Name;
			masterRec.Date__c = updatedate;
			masterRec.Master_Name__c= debtor.Debtor_Name__c;
			masterRec.Credit__c= debtor.Credit_formula__c;
			masterRec.Debit__c= debtor.Debit_formula__c;
			insertList.add(masterRec);
		}
	}
	else{
		if(dateSet.contains(updatedate)){
			mapOfMasterWithName.get(trigger.new[0].Name).Credit__c = trigger.new[0].Credit_formula__c;
			mapOfMasterWithName.get(trigger.new[0].Name).Debit__c = trigger.new[0].Debit_formula__c;
		}
		else{
			for(Debtors_Ledger__c debtor : allDebtor){
				masterRec = new MasterCopy__c();
				masterRec.Master_Code__c= debtor.Name;
				masterRec.Date__c = updatedate;
				masterRec.Master_Name__c= debtor.Debtor_Name__c;
				masterRec.Credit__c= debtor.Credit_formula__c;
				masterRec.Debit__c= debtor.Debit_formula__c;
				insertList.add(masterRec);
			}
		}
	}
	insertList.addAll(mapOfMasterWithName.values());
	upsert insertList;
}
If any of the case is not working than please le me know.
You can contact me on hangout at : abhishek.bansal@metacube.com.

Regards,
Abhishek
 
SFDC DummySFDC Dummy
showing this error Visualforce Error Help for this Page System.DmlException: Upsert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, UpsertMasterNew1: execution of AfterUpdate caused by: System.SObjectException: SObject row was retrieved via SOQL without querying the requested field: Debtors_Ledger__c.Credit_formula__c Trigger.UpsertMasterNew1: line 20, column 1: [] Error is in expression '{!save}' in component in page bankbookmodification: Class.ManageListController1.save: line 104, column 1 Class.ManageListController1.save: line 104, column 1
Abhishek BansalAbhishek Bansal
Change Code :
 
trigger UpsertMasterNew on Debtors_Ledger__c(after insert,after update) {
	List<Debtors_Ledger__c> allDebtor = new List<Debtors_Ledger__c>([Select DailyUpdate__c,Name,Debtor_Name__c from Debtors_Ledger__c]);
	List<MasterCopy__c> allMasterData = new List<MasterCopy__c>([Select Name,Date__c,Master_Code__c,Master_Name__c,Credit__c,Debit__c from MasterCopy__c]);
	Map<String,MasterCopy__c> mapOfMasterWithName = new Map<String,MasterCopy__c>();
	Set<Date> dateSet = new Set<Date>();
	for(MasterCopy__c master : allMasterData){
		mapOfMasterWithName.put(master.Master_Code__c,master);
		dateSet.add(master.Date__c);
	}
	
	List<MasterCopy__c> insertList = new List<MasterCopy__c>();
	MasterCopy__c masterRec;
	Date updatedate = trigger.new[0].DailyUpdate__c;
	if(allMasterData.size() == 0){
		for(Debtors_Ledger__c debtor : allDebtor){
			masterRec = new MasterCopy__c();
			masterRec.Master_Code__c= debtor.Name;
			masterRec.Date__c = updatedate;
			masterRec.Master_Name__c= debtor.Debtor_Name__c;
			masterRec.Credit__c= debtor.Credit_formula__c;
			masterRec.Debit__c= debtor.Debit_formula__c;
			insertList.add(masterRec);
		}
	}
	else{
		if(dateSet.contains(updatedate)){
			mapOfMasterWithName.get(trigger.new[0].Name).Credit__c = trigger.new[0].Credit_formula__c;
			mapOfMasterWithName.get(trigger.new[0].Name).Debit__c = trigger.new[0].Debit_formula__c;
		}
		else{
			for(Debtors_Ledger__c debtor : allDebtor){
				masterRec = new MasterCopy__c();
				masterRec.Master_Code__c= debtor.Name;
				masterRec.Date__c = updatedate;
				masterRec.Master_Name__c= debtor.Debtor_Name__c;
				masterRec.Credit__c= debtor.Credit_formula__c;
				masterRec.Debit__c= debtor.Debit_formula__c;
				insertList.add(masterRec);
			}
		}
	}
	insertList.addAll(mapOfMasterWithName.values());
	upsert insertList;
}

 
This was selected as the best answer
Abhishek BansalAbhishek Bansal
Change line no. 2 with below line :

List<Debtors_Ledger__c> allDebtor = new List<Debtors_Ledger__c>([Select DailyUpdate__c,Name,Debtor_Name__c,Credit_formula__c,Debit_formula__c from Debtors_Ledger__c]);
SFDC DummySFDC Dummy
same error coming at the time of updating Visualforce Error Help for this Page System.DmlException: Upsert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, UpsertMasterNew1: execution of AfterUpdate caused by: System.SObjectException: SObject row was retrieved via SOQL without querying the requested field: Debtors_Ledger__c.Credit_formula__c Trigger.UpsertMasterNew1: line 20, column 1: [] Error is in expression '{!save}' in component in page bankbookmodification: Class.ManageListController1.save: line 104, column 1 Class.ManageListController1.save: line 104, column 1
Abhishek BansalAbhishek Bansal
Please contact me on hangout, I have provided you my email id in above post or contact me on skype. Skype Id : abhishek.bansal2790
SFDC DummySFDC Dummy
its working fine...but not updated the value.its taking only first record value.....