I was working on a bank management App. and as a feature, I created a batch that is supposed to do a deposit regularly every three months. And the requirement was that I use a custom metadata for the percent of deposit being done. But I'm failing to do so with the code below. Can someone help me with this?

public class interestTransaction implements Database.Batchable<SObject>, Schedulable {
    public Database.QueryLocator start(Database.BatchableContext BC){
        return Database.getQueryLocator('SELECT Id, Balance__C FROM Bank_Account__c');
    public void execute(Database.BatchableContext BC, List<Bank_Account__c> scope){
        List<Transaction__c> transactions = new List<Transaction__c>();
        Interest_Rate__mdt ir = [SELECT Interest_rate__c FROM Interest_Rate__mdt]; 
        for(Bank_Account__c trans : scope){
            Decimal amount = trans.Balance__c * ir;
            Transaction__c tran  = new Transaction__c();
            tran.Type__c = 'Deposit'; 
            tran.Bank_Account__c = trans.Id;
            tran.Amount__c = amount ;
         insert transactions;
    public void finish(Database.BatchableContext BC){
    public void execute(SchedulableContext sc){
        interestTransaction interestTransactionInstance = new interestTransaction();

I'm getting this error:

Arithmetic expressions must use numeric arguments


The error is here:

    Decimal amount = trans.Balance__c * ir;

You're trying to multiply a record against a number. This is not allowed. You probably meant:

    Decimal amount = trans.Balance__c * ir.Interest_rate__c;
  • solved my problem. Thanks!
    – sfdxnewbie
    Oct 10 '21 at 18:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.