You need to sign in to do that
Don't have an account?
apex code share
Please help me writing a trigger for preventing duplicate record to be saved on custom object.
Hi,
I have a custom object name "Product Segments" and when someone click new to enter new product segments then it should check whether the record already exist or not ,,if exist then it should throw an error
trigger should check on these field "Product Segment Name",,"Product Segment Code" and "Product Category Name".
if any record consist of same values in above field which already exists in system then it should not be saved.
Nilesh also correct.
Here is code for your requirement.
If a reply to a post answers your question or resolves your problem, please mark it as the solution to the post so that others may benefit.
All Answers
You can do it using validation rules also. Its easy.
Another way is.. go to Product Segments object. Go to Product Segment Name. Click on "Edit". And check the checkbox for unique
You can do this for remaining two fields also.No need to write validation /Trigger.
Nilesh also correct.
Here is code for your requirement.
If a reply to a post answers your question or resolves your problem, please mark it as the solution to the post so that others may benefit.
Thank a lot for your help :-)
but i'm getting error Error: Compile Error: unexpected token: ':'
for this part :-
Try this....
WHERE Product_Segment_Name__c IN :psName
AND Product_Segment_Code__c IN :psCode
AND Product_Category_Name__c IN :categoryName]
Thanks!!
I used =: and it worked :-)
WHERE Product_Segment_Name__c IN =:psName
AND Product_Segment_Code__c IN =:psCode
AND Product_Category_Name__c IN =:categoryName]
Sorry, my bad
IT must be IN: instead of :IN
Use following