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
Gouse Mohiddin 4Gouse Mohiddin 4 

help me out here

Controller:
public class BankAccuont_TransactionStatus {
    public static void TransactionStatus(){
            List<Bank_Account__c> BankList = new List<Bank_Account__c>();
            List<Bank_Account__c> BList=[select id,Name,Account_Type__c,Number_Of_Transaction__c,Status__c from Bank_Account__c];
        for(Bank_Account__c b:BList){
            Bank_Account__c baccnt = new Bank_Account__c();
            if(b.Account_Type__c =='Current' && b.Number_Of_Transaction__c <=5){
                    baccnt.Status__c = 'Red';                  
                }
                else if(b.Account_Type__c=='Current' && b.Number_Of_Transaction__c == 6 || b.Number_Of_Transaction__c ==10){
                    baccnt.Status__c = 'Yellow';                    
                } 
            else if(b.Account_Type__c=='Current' && b.Number_Of_Transaction__c >= 10){
                    baccnt.Status__c = 'Green';
            }
            BankList.add(baccnt);            
        }
      // update BankList;
                
    }
}
=====================================================
trigger:
trigger Update_Status_Based_On_Transactions on Bank_Account__c (after insert,after update) {
    
    BankAccuont_TransactionStatus.TransactionStatus(trigger.new);
}
Best Answer chosen by Gouse Mohiddin 4
Sami ShakithSami Shakith
Hey Gouse,

You forgot to give the account list parameter on the transactionStatus method. Try the below code.
public class BankAccuont_TransactionStatus {
    public static void TransactionStatus(List<Bank_Account__c> BList){
            List<Bank_Account__c> BankList = new List<Bank_Account__c>();
            
        for(Bank_Account__c b:BList){
            Bank_Account__c baccnt = new Bank_Account__c();
            if(b.Account_Type__c =='Current' && b.Number_Of_Transaction__c <=5){
                    baccnt.Status__c = 'Red';                  
                }
                else if(b.Account_Type__c=='Current' && (b.Number_Of_Transaction__c == 6 || b.Number_Of_Transaction__c ==10)){
                    baccnt.Status__c = 'Yellow';                    
                } 
            else if(b.Account_Type__c=='Current' && b.Number_Of_Transaction__c >= 10){
                    baccnt.Status__c = 'Green';
            }
            BankList.add(baccnt);            
        }
                
    }
}
If it helps you mark this answer as best.

Happy Coding!!
 

All Answers

Gouse Mohiddin 4Gouse Mohiddin 4
Above code is not working
 
Oleg IshchukOleg Ishchuk
Hello, Gouse!
Could you explain the logic which you want to implement?
Gouse Mohiddin 4Gouse Mohiddin 4
Hi, I have two objects one is transaction & BankAccount.MD Relationship b/w them,so I want to update status field on bank account object whenever account type is "current account" and number of transactions like ==6 then status will be "yellow". This is my requirement plz help me out here Thanks, Gouse
Oleg IshchukOleg Ishchuk
Which mistake do you have?
Gouse Mohiddin 4Gouse Mohiddin 4
Hi, I don't know where I did mistakes Thanks, Gouse
Oleg IshchukOleg Ishchuk
You have to open Developer console. After firing trigger you can see mistakes which you are received.
Sami ShakithSami Shakith
Hey Gouse,

You forgot to give the account list parameter on the transactionStatus method. Try the below code.
public class BankAccuont_TransactionStatus {
    public static void TransactionStatus(List<Bank_Account__c> BList){
            List<Bank_Account__c> BankList = new List<Bank_Account__c>();
            
        for(Bank_Account__c b:BList){
            Bank_Account__c baccnt = new Bank_Account__c();
            if(b.Account_Type__c =='Current' && b.Number_Of_Transaction__c <=5){
                    baccnt.Status__c = 'Red';                  
                }
                else if(b.Account_Type__c=='Current' && (b.Number_Of_Transaction__c == 6 || b.Number_Of_Transaction__c ==10)){
                    baccnt.Status__c = 'Yellow';                    
                } 
            else if(b.Account_Type__c=='Current' && b.Number_Of_Transaction__c >= 10){
                    baccnt.Status__c = 'Green';
            }
            BankList.add(baccnt);            
        }
                
    }
}
If it helps you mark this answer as best.

Happy Coding!!
 
This was selected as the best answer
Gouse Mohiddin 4Gouse Mohiddin 4
Thanks Sam