You need to sign in to do that
Don't have an account?
santhosh konathala 17
Hi Community I am learner of Apex coding.I written a class avoids duplicate records but showing an error ''Loop variable must be of type SObject at line 11 column 13 ".please help me how to resolve this?Below is my class?
public class AvoidduplicateAccount{
public void AvoidDupliacteRecords(Account[] acc)
{
set<string> set1=new set<string>();
for(account a:[select id,name from Account])
{
set1.add(a.name);
}
for(Account d:Trigger.new)
{
if(set1.contains(d.name))
{
d.adderror('plz insert unique values');
}
}
}
}
public void AvoidDupliacteRecords(Account[] acc)
{
set<string> set1=new set<string>();
for(account a:[select id,name from Account])
{
set1.add(a.name);
}
for(Account d:Trigger.new)
{
if(set1.contains(d.name))
{
d.adderror('plz insert unique values');
}
}
}
}
I hop it helps you
Please mark it best ansert if it helps you so it make proper solution for others :)
All Answers
public class AvoidduplicateAccount{
public void AvoidDupliacteRecords(Account[] acc){
set<string> set1=new set<string>();
for(account a:[select id,name from Account]){
set1.add(a.name);
}
for(Account d:acc){
if(set1.contains(d.name)){
d.adderror('plz insert unique values');
}
}
}
}
Thanks
let me inform if it work
I hop it helps you
Please mark it best ansert if it helps you so it make proper solution for others :)
Variable does n't exit 'Name'