You need to sign in to do that
Don't have an account?
MT0478
Check for duplicates and Check a checkbox
Hi,
I'm new to Apex, and please advise me about Apex Trigger.
I could create a trigger for custom object to find duplicates and check a checkbox.
Below is my code. This trigger can check the checkbox of new record.
But I want to check the existing record's one.
How can i do this?
trigger CheckIsRevised on No__c (before insert, before update) { if (Trigger.isInsert) { for (No__c no : Trigger.new){ No__c[] nos= [select id from No__c where Ano__c = :no.Ano__c ]; if (nos.size() > 0) { no.revised_flag__c=true; } } } else if (Trigger.isUpdate) { for (No__c no : Trigger.new) { No__c oldNo=Trigger.oldMap.get(no.id); if (no.Ano__c != oldNo.Ano__c) { No__c[] nos= [select id from No__c where Ano__c = :no.Ano__c]; if (nos.size() > 0) { no.revised_flag__c=true; } } } } }
Thanks in advance!
You cantry this one
All Answers
You cantry this one
Thanks to your code, i could implement the trigger properly.
Thank you, Mr? Shashikant Sharma:smileyhappy:
Hi,
I have gone through this trigger.
I want to avoid adding duplicate record. If user is adding a duplicate Name then message is diplayed on user interface and that particular record should not get save. The record should save only when it is not the duplicate value.
Cheers,
Devendra S