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
manjunath vivekmanjunath vivek 

Adderror method doesn't display error message, i tried the following Trigger.New[0].name.adderror('Duplicate entry found. There already exists an entry for the same Record. Please update the old one');

Adderror method doesn't display error message, i tried the following Trigger.New[0].name.adderror('Duplicate entry found. There already exists an entry for the same Record. Please update the old one');
RadnipRadnip
Is there a reason why your adding the [0], is zero hard coded in your code? What other code do you have? as this looks good to me (except the 0)
RadnipRadnip
Is it a before or after trigger?
Prem_PalPrem_Pal
Your trigger code would help us here!
Tony TannousTony Tannous
If you are working in a specific VF, make sure that <apex:message> exist in the page.


Regards 
manjunath vivekmanjunath vivek
My code is as follows.
Trigger duplicates on account(before insert){

if(trigger.new[0].Name==trigger.old[0].name)
{
;
Trigger.New[0].name.adderror('Duplicate entry found. There already exists an entry for the same Record. Please update the old one');
}
}
manjunath vivekmanjunath vivek
Trigger duplicates on account(before insert){

if(trigger.new[0].Name==trigger.old[0].name)
{

Trigger.New[0].name.adderror('Duplicate entry found. There already exists an entry for the same Record. Please update the old one');
}
}
Tony TannousTony Tannous
Hi,

if you are using a before insert tigger , the value of trigger.old is null.

so what i suggest for you to do the below

1- put all the value of trigger.new[0].Name in a list of string.
2- select the account object and put a where conidtion that name in the list of string created.
3- after that you need to verify it exist or not.

Good Luck