You need to sign in to do that
Don't have an account?
aswanijagadesh1.397398535585991E12
insert new account by using trigger?
hai friends
if account name is alerady exit then display error message ,other wise insert new account. for this i wrote like this
trigger DuplicateAcc on Account(after insert) {
List<Account> acc=[select id,name from account];
public account acc1;
//system.debug('1111111'+acc.size());
for (Account acct:Trigger.new) {
for(Account a:acc)
{
if(acct.name==A.name)
{
acct.addError('ERROR: there is already an identical record Name in Data Base: <a href=\'https://na1.salesforce.com/' + a.id + '\'+ target="_blank">'+ a.id+'</a>',false);
return;
}
//acc1=new account(name=acct.name);
//insert acc1;
}
// system.debug('********'+acct.name);
// acc1=new account(name=acct.name);
//insert acc1;
//break;
}
}
insert is not done please how can i do this guide me urgent
if account name is alerady exit then display error message ,other wise insert new account. for this i wrote like this
trigger DuplicateAcc on Account(after insert) {
List<Account> acc=[select id,name from account];
public account acc1;
//system.debug('1111111'+acc.size());
for (Account acct:Trigger.new) {
for(Account a:acc)
{
if(acct.name==A.name)
{
acct.addError('ERROR: there is already an identical record Name in Data Base: <a href=\'https://na1.salesforce.com/' + a.id + '\'+ target="_blank">'+ a.id+'</a>',false);
return;
}
//acc1=new account(name=acct.name);
//insert acc1;
}
// system.debug('********'+acct.name);
// acc1=new account(name=acct.name);
//insert acc1;
//break;
}
}
insert is not done please how can i do this guide me urgent
All Answers
the mistake is you have written trigger on after Insert. which is wrong for your requirement.
It should be on before Insert and update.
see below example for your requirement.
Apex Trigger:
Thank You,
Hitesh Patel
SFDC Certified Developer & Administrator & Advanced Administrator & Sales cloud consultant
Email :- hiteshpatel.aspl@gmail.com
My Blog:- http://mrjavascript.blogspot.in/
trigger DuplicateAcc on Account(before insert) {
List<Account> acc=[select id,name from account];
public account acc1;
for (Account acct:Trigger.new) {
for(Account a:acc)
{
if(acct.name==A.name)
{
acct.addError('ERROR: there is already an identical record Name in Data Base: <a href=\'https://na1.salesforce.com/' + a.id + '\'+ target="_blank">'+ a.id+'</a>',false);
return;
}
}
}
}
i want to mass insert of accounts by using data loader at that time duplicate records will show error remainling will insert