Now that you've clarified your requirements, it appears to me that you have several options available to you for doing this validation.
Personally, I'm not fond of the beforeInsert trigger solution. Since this is only on one object, you could add a field to the user object that keeps track of the LastCreatedDateZeiteintrag__c
which could be used in a validation rule. Most fields on the user object can't be updated using a trigger, but they can be updated using workflow. Triggers also require periodic maintenance of code where workflow does not.
What I would recommend is comparing System.Now()
, Today()
or the TODAY value of the new CreatedDate
(a date-time value) with the LastCreatedDateZeiteintrag__c
on the User to create your validation rule. If the record passes, you'll then want to use workflow to update the LastCreatedDateZeiteintrag__c
(either as a Date-time or Date, depending on your requirements) for that user with the new CreatedDate
for the record. This method doesn't require you to maintain any code and equally important, gives you an error message that will appear where ever you want it to be located on your page.
Another option you'd have would be to create a controller extension that queries the user Zeiteintrag__c
record along with user for the last record that user created and compares that with either Now()
or Today()
. If the number is less than one day, a page message error is generated, preventing the record from being saved.
Zeiteintrag__c
each day, or do you want to prevent a more than one newZeiteintrag__c
related record from being created each day that's a child ofStundenkonto__c
, regardless of who the user is? The solution to each problem is different.