+ Start a Discussion
Campbell StrasCampbell Stras 

Workflow rule, process or trigger to prevent daily record duplication.

Attempting to create a Weekly Time Sheet system where users have to create Daily Time Card records. If there is a Daily Time Card detail record already created for that day on the Weekly TIme Sheet master record, is there a way to use a validation rule or perhaps a beforeinsert trigger to prevent a duplicate record from being created on the same day by that user? 
Best Answer chosen by Campbell Stras
RD@SFRD@SF
Hi Cambell,

Do this in two ways:

Config:

1.Create a new field on Daily Time Cards, say 'uDay', set the field as unique and case sensitive as true.
2. Create a workflow with on the Daily Time cards which triggers on create of the record and updates the unique field
"employee name/employee id"+ "today"
Activate the workflow.
3. Now each time the record is created it would check if the value in the uDay field is unique, if the same user tries to create the card for the same day, it would through a validation error.

Code:

You would have to write a before insert trigger, which checks if for the current user the day card exists, and stop the records create

Please follow the link (https://help.salesforce.com/articleView?id=custom_field_attributes.htm&type=0)to know more about the unique fields

Hope it helps
RD 

All Answers

RD@SFRD@SF
Hi Cambell,

Do this in two ways:

Config:

1.Create a new field on Daily Time Cards, say 'uDay', set the field as unique and case sensitive as true.
2. Create a workflow with on the Daily Time cards which triggers on create of the record and updates the unique field
"employee name/employee id"+ "today"
Activate the workflow.
3. Now each time the record is created it would check if the value in the uDay field is unique, if the same user tries to create the card for the same day, it would through a validation error.

Code:

You would have to write a before insert trigger, which checks if for the current user the day card exists, and stop the records create

Please follow the link (https://help.salesforce.com/articleView?id=custom_field_attributes.htm&type=0)to know more about the unique fields

Hope it helps
RD 
This was selected as the best answer
Campbell StrasCampbell Stras
That’s a great idea, Deepak. I will implement that and post results. Thank you, Campbell
Campbell StrasCampbell Stras
The Config works perfectly, Deepak. Thanks again. Campbell.
RD@SFRD@SF
Hi Campbell

Happy to help

RD
Jean Grey 10Jean Grey 10
This is great and works perfectly, thank you? Are we able to change the error message that appears?
Campbell StrasCampbell Stras
Hi Jean,
Tha's a great question. I do not know of any way to change the error message that appears.
Campbell