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
bhanu challengebhanu challenge 

can u tel the error

plz check  it............its about triggers
Best Answer chosen by bhanu challenge
Ginto MathewGinto Mathew
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');
			
			}
		}
	}
}