+ Start a Discussion
salesforce studysalesforce study 

Initial term of field expression must be a concrete SObject: LIST at line 6 column 9

Trigger updateamount on Fund_Transfer__c (before update) {
    Fund_Transfer__c[] transfer;
    Fund_Transfer__c fund = Trigger.new[0];
    transfer = [SELECT Amount__c,Account_No__c FROM Fund_Transfer__c WHERE Account_No__c =: fund.Account_No__c ];
    if(transfer.size()>0){
        transfer.Amount__c = transfer.Amount__c + fund.Amount__c;
        update transfer;
    }
    else{
        system.debug('sorry transaction stopped');
    }             
}

 

 

please help me to correct this error

harsha__charsha__c

Hi

 

You went wrong in the followed line

 

  transfer.Amount__c = transfer.Amount__c + fund.Amount__c;

 You can not directly access the list data in above pattern

 

You need to iterate through the list (transfer) for the values.

 

 

jd123jd123

hey you can do like this

 

transfer[0].Amount__c = transfer[0].Amount__c + fund.Amount__c;

 

this is the not the right way.

 

Can you expalin me your senario i can help you out 

 

Vinit_KumarVinit_Kumar

If I understood your requirement correctly, below code should work for you,

 

Trigger updateamount on Fund_Transfer__c (before update) {

List<Id> accIdList = new List<Id>();
List<Fund_Transfer__c> transfer = new List<Fund_Transfer__c>();
List<Fund_Transfer__c> updatedtransfer = new List<Fund_Transfer__c>();

for(Fund_Transfer__c fund : trigger.new){
accIdList.add(fund.Account_No__c); //(Assuming Account_No__c is a relationship field)
}
transfer = [SELECT Amount__c,Account_No__c FROM Fund_Transfer__c WHERE Account_No__c in: accIdList ];


for(Fund_Transfer__c fu :trigger.new){
for(Fund_Transfer__c f : transfer)
if(transfer.size()>0){
f.Amount__c = f.Amount__c + fu.Amount__c;
updatedtransfer.add(f);
}
else{
system.debug('sorry transaction stopped');
}
update updatedtransfer;

}
}