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
cyrilvercyrilver 

Global variable in apex trigger

Hi,

 

I have written a trigger (on before insert) which control duplicate account when a user create a new account.

The first time the user save the record, I display the list of duplicate account with the addError function.

I would like when the user uses the "Save" button another time to create the account and not display error message.

The idea is to alert the user an not to block him.

 

I try to do this with :

- variable custom settings but when addError is used, my variable is not updated,

- cookies,

- ...

 

Is there any solution ? Thanks.

 

Regards.

 

dfiredfire

well, you could create a hidden boolean called warned set to false.

 

when your trigger runs and shows the error msg, set warned = true.

 

when the user saves again, check the warned flag and if true, set to false and save record.

cyrilvercyrilver

I've tried this solution.

But when you set the warned field to true in the trigger, the addError function realise a rollback so the warned field value is false.

Have you another idea ?

Thanks. Regards.

cyrilvercyrilver

Has someone else another solution ?

Thanks.

 

Regards,