Trigger to check duplicate name to custom object in Salesforce

Vijay Kumar
2 min readAug 6, 2020
Trigger to check duplicate name to custom object in Salesforce

Hey guys, today in this post we are going to learn about How can we prevent duplicate name insert on custom object in Salesforce.

Real time scenarios:- Write a trigger on custom object When a Object (childObjTrigger__c) is being created, if a record exists with the same EmployeeName (EmployeeName__c), the trigger should throw an error.

Create a custom object with custom field name as EmployeeName

Custom Object:- childObjTrigger__c >> custom field:- EmployeeName__c (Text
type)

Files we used in this post example:-

childTriggerhandler.apxt

Apex Class Trigger

It is used for prevent duplicate record creation with same name

childObjHandler.apxc

Apex Class Handler

It is call into cildTriggerhandler.apxt file.

Custom Field:- EmployeeName__c

Custom Child Object with Custom Field

It is custom object with custom field used for display an error if same name being inserted.

You can download file directly from github by click here Final Output

Other post that would you like to learn

Step 1:- Apex Class Trigger : childTriggerhandler.apxt

From Developer Console >> File >> New >> Apex Trigger

childTriggerhandler.apxt [Apex Class Trigger]

Step 2:- Apex Class : childObjHandler.apxc

From Developer Console >> File >> New >> Apex Class

childObjHandler.apxc [Apex Class Handler]

Other related post that would you like to learn

Originally published at https://www.w3web.net on August 6, 2020.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

No responses yet

Write a response