Hi Bhanu, SOQL query results are always returned as a list, unless you use LIMIT 1 in the query. Also please do not use SOQLs (both select and DML queries) in 'for' loops I have tried modifiying the code, this should do the job,
trigger op_t1 on Opportunity (before insert){
List<String> oppAccIdList = new List<String>();
List<Account> accList = new List<Account>();
for(Opportunity opp: trigger.new){
oppAccIdList.add(opp.Account.Id);
}
if(!oppAccIdList.isEmpty()){
accList = [SELECT Name,Industry FROM Account WHERE Id IN =: oppAccIdList];
}
if(!accList.isEmpty()){
for(Account acc : accList){
if(acc.Industry == 'Education'){
acc.addError('It\'s Error');
}
}
}
}
SOQL query results are always returned as a list, unless you use LIMIT 1 in the query.
Also please do not use SOQLs (both select and DML queries) in 'for' loops
I have tried modifiying the code, this should do the job,