You need to sign in to do that
Don't have an account?
naveen p
Error while writing a trigger
Hi Everyone,
i m new to SFDC. I m writing a basic trigger by using handler class for avoiding duplicate values but it is giving an error.
my code is
trigger AvoidingDuplicateValues1 on Account (Before Insert,Before Update)
{
DuplicateValue dup=new DuplicateValue();
}
Error: Compile Error: Invalid type: DuplicateValue at line 3 column 28
Pls help.
i m new to SFDC. I m writing a basic trigger by using handler class for avoiding duplicate values but it is giving an error.
my code is
trigger AvoidingDuplicateValues1 on Account (Before Insert,Before Update)
{
DuplicateValue dup=new DuplicateValue();
}
Error: Compile Error: Invalid type: DuplicateValue at line 3 column 28
Pls help.
Please Re-check the name of your apex class and the name you used in Trigger.
Class name is "DuplicateVaiue" where as in trigger you used "DuplicateValue".
Please find the revised code.
Please let me know if it helps you.
Regards,
Onesh.K
All Answers
Your Trigger has no Erors, Can you post the Helper Class.
Thanks for ur reply..
public class DuplicateVaiue
{
public void dup(List<Account> TriggerNew)
{
Set<String>accSet=new Set<string>();
for(Account acc:trigger.new)
{
accSet.add(acc);
}
List<Account>listacc=[select name from account where name in :accset];
Map<String,Account>mapacc=new Map<String,Account>();
for(Account objacc:ListofAccount)
{
mapacc.put(objacc.name,objacc);
}
for(Account objacc:Trigger.new)
{
if(mapacc.containskey(objacc.name))
{
objacc.adderror('Nmae already eists');
}
}
}
}
please tell me where i was wrong
Thanks in advance
Naveen
Please find the below code:
Here I handled :
(1) Naming Convention.
(2) Alignment.
(3) Corrected the logic.
Please do let me know if it helps you.
Regards,
Mahesh
Please Re-check the name of your apex class and the name you used in Trigger.
Class name is "DuplicateVaiue" where as in trigger you used "DuplicateValue".
Please find the revised code.
Please let me know if it helps you.
Regards,
Onesh.K
i am able to restrict the duplicate name entries,but i am unable to edit remaining fiels of the recod means i want to change a particular field value but i am unable to do.
it is throwing an error " NAME AREADY EXISTS"
please advice
Naveen.