You need to sign in to do that
Don't have an account?

Does a Before Insert trigger work to populate required fields?
It would seem that the answer is no - though that doesn't make sense.
Basically, I am trying to write a before insert trigger to populate the Name (official) field of a custom object. I have read a number of messages that are very close to this one - but not quite. Some folks recommend creating a VisualForce page, but I am trying to do it on a standard Salesforce form.
When I enter a new record, I get a message back saying "Invalid Data", "You Must Enter a Value". Now, this trigger works fine if I have it autopopulate a different, non-required field, it's fine. However, if I try to use it with the object's Name field or even another field that I have set to required, it fails. Does this sort of process not work , or am I mssing something?
Many thanks.
Message Edited by ksnyder on 10-02-2008 03:07 PM
Basically, I am trying to write a before insert trigger to populate the Name (official) field of a custom object. I have read a number of messages that are very close to this one - but not quite. Some folks recommend creating a VisualForce page, but I am trying to do it on a standard Salesforce form.
When I enter a new record, I get a message back saying "Invalid Data", "You Must Enter a Value". Now, this trigger works fine if I have it autopopulate a different, non-required field, it's fine. However, if I try to use it with the object's Name field or even another field that I have set to required, it fails. Does this sort of process not work , or am I mssing something?
Code:
trigger updateEnrollmentRecordName on Enrollment__c (before insert, after update) { List<Enrollment__c> updatedEnrollment = new List<Enrollment__c>(); for (Enrollment__c e : trigger.new){ e.Name = e.Enrollee_Name_Text__c + ' - ' + e.Program_Name__c + ' ' + e.Cycle__c + ' ' + e.Cycle_Year__c; updatedEnrollment.add(e); } }
Many thanks.
Message Edited by ksnyder on 10-02-2008 03:07 PM
The fields are displayed on the web form [Ah-hah! If I removed the field from the form and had it trigger quietly in the background, would it work? - I will try that and post the results].
It isn't crucial that the Name field be populated on the form as the user is entering the record. It's more for later on, when they need to select the record from various list views.
The main reason I am trying to figure this out is so that I can make the Name fields more informative for users. I had originally set it as an autonumber, but having the contact name and some enrollment info in the field would be more friendly for the end user.
Thanks again.
You can definitely do an insert quietly at the beginning and then immediately redirect to the standard edit page of the new record (which will have the values you wrote). It breaks workflow and stuff for that object, but if it's just your custom object, you're fine.
See if you get any better answers also! It seems like with a custom object, there may be a way to set a default or just hide it using FLS or remove Name / Number from the page layout. For some standard fields, you can't take them out of the page layout, but you can still use FLS to make it illegal for the user to see them, which avoids having it show up in the editor.
When you say that you would insert quietly at the beginning and then redirect to the standard edit page, is this most effectively done via S-Controls or Visualforce pages? I am leaning toward Visualforce pages.
Thanks .