Skip to main content
bharath kumar mandava a posé une question dans #Ask An Expert
trigger accountduplicatetrigger on account(before insert,before update)

 

{

 

for(account a:trigger.new)

 

{

 

list<account>acc=[select id from account where name=:a.name and rating=:a.rating];

 

if(acc.size()>0)

 

{

 

acc.NAME.addError('you cannot create the duplicate account');

 

}

 

}

 

}
2 réponses
  1. 23 janv. 2014, 10:45
    Hi Bharath,

     

    In your code, acc is a List<Account>. So you cannot directly access Name field from acc. Instead either you can use

     

    acc[0].Name.addError('you cannot create the duplicate account');

     

    OR

     

    For(Account a : acc)

     

    {

     

        a.NAME.addError('you cannot create the duplicate account');

     

    }

     

    Thanking you,

     

    Arun
0/9000