1
trigger OpportunityAmount on Opportunity (before insert) {

    List<String> stage=new List<String>();
    For(Opportunity opp:Trigger.New){
        stage.add(opp.StageName);
    }
    List<Opportunity> stageopp=[select StageName from Opportunity where StageName=:stage];
     if(stageopp.StageName =='Closed won'){////<---- Error
        for(Opportunity opp:Trigger.New){
            opp.addError('Amount field is a required field');
        }
    }

}

While saving above trigger, i am getting following. Please help me in this.

Initial term of field expression must be a concrete SObject: List

  • 1
    stageopp is list here. you can use list.fieldName ie. stageopp.StageName... you need to use stageopp[0].StageName this way it will check only one sobject field.. not sure what is the business requirement. – Ratan Paul Apr 18 '16 at 11:10
  • ohh typo mistake ... stageopp is list here. you can't use list.fieldName ie. stageopp.StageName. – Ratan Paul Apr 18 '16 at 11:22
1

stageopp is a list of Opportunity according to your code. You should have a for loop to access the Opportunities inside it.

for(Opportunity oppRec : stageopp)
{
if(oppRec.StageName =='Closed won'){
    for(Opportunity opp:Trigger.New){
        opp.addError('Amount field is a required field');
    }
}
}

One more thing, your SOQL query is having a where clause where it searches for stagename inside a list, so having = there might not work, try using IN instead.

List<Opportunity> stageopp=[select StageName from Opportunity where StageName IN :stage];
0

your problem is that stageopp is of type list, and stagename is of type Opportunity, in order to access the stagename of your stageopp object you would need to do stageopp[i].StageName where i is the index

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.