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
System Administrator 393System Administrator 393 

Apex Class Development for

I have a written an apex class for a custom object called loan disbursement transactions. This custom object is a child object to the account. I have a currency field on the account record that calculates the sum of the loan disbursement transaction value, each of these values are coming from the child object, loan disbursement transaction. Usually there are only 2 such values. When I try to run this apex code, the total disbursements field on the account record does not update. Can someone please help me with what I am doing wrong? The apex code is below: 

public class UpdateLoantransactions{


  public static List<Loan_Disbursement_Transactions__c> listoftransactions(Account b){
  List<Loan_Disbursement_Transactions__c> transactions1 = [SELECT Name, Disbursement__c, Account__c, Loan_Disbursement_Value__c FROM Loan_Disbursement_Transactions__c WHERE Account__c =: b.Name];
 
  return transactions1;
 }
  
 public static decimal gettransactionvalue1(Account b2){
 decimal d = 0.00;
 
 if((listoftransactions(b2)).size()>0){
 d = (((listoftransactions(b2)).get(0)).Loan_Disbursement_Value__c);}
 
 return d;
 }
 
 public static decimal gettransactionvalue2(Account b3){
 decimal d1 = 0.00;
 
 if(((listoftransactions(b3)).get(1))!=null){
 d1 = (((listoftransactions(b3)).get(1)).Loan_Disbursement_Value__c);}
 return d1;
 }
 
 public static decimal gettotaldisbursements(Account b4){
 decimal d2 = 0.0;
 d2 = gettransactionvalue1(b4) + gettransactionvalue2(b4);
 b4.Total_Disbursement__c = d2;
  return b4.Total_Disbursement__c;
 }
 }

Thanks
ANUTEJANUTEJ (Salesforce Developers) 
Hi there,

In your implementation are you getting any errors as such and also could you check what are the values being returned and what are the values being used using system.debug statements along with these details could you please provide an example so that we can check this further.

Looking forward for your response.

Regards,
Anutej 
System Administrator 393System Administrator 393
Hello,

Thanks for your response.No value is being returned for now on the total disbursement field in the account record. The trigger being used to update the field is 


trigger Updateloantransactions on Account (before update) {

 for (Account c : Trigger.new){
 
     if(c.loan__Borrower__c == true){
     UpdateLoantransactions.gettotaldisbursements(c);}
     }
}
Thanks,
Priyal