function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
SOPORTE TISOPORTE TI 

Default values before create a NEW register in any object

How can i do this with any object?  VFPage?  Triggers?   ApexClass?
Please, it's a critical problem for my partners!!!

User-added image

User-added image
RishavRishav
Hiii,
       if  you are using the apex class with visualforce then you can set the default vaule in your function that is going to perform insert or update operation.
 you can also use the trigger to do this. Write the trigger on insert and update event and assign the default in the field in which that you want. 
SOPORTE TISOPORTE TI
Hi Rishav, thanks for you answer.

The trigger way, is useful to put default values AFTER i press the save button. But mi problem is, make visible default values in the beginning, before i press save.

I try to put default values at the moment to create a new register, but the triggers are always activated after i press the save button.

It's possible resolve this problem making a trigger?
RishavRishav
If you are using the visualforce pages then it is very easy to do but with  standard salesforce page it's tricky . So you can do one thing make a visualforce page for creating you register and show the default value while creation of new record with <apex:outputText>so it will not be editable and accept the input in other fields and make this visualforce page as a tab . In this way you can solve your problem. No need to write any trigger.
SOPORTE TISOPORTE TI
Hi Venkat, thanks for your answer.

I'm not that sure if it's the right way to resolve this problem. 
It works, but i wanna try to see if it's possible to resolve this problem using triggers or Apex Class.
I believe if we used hack URL it's not a "correct" way to resolve this problem. I try to burn all my options before y code this solution.

If it's not possible in other way, i'm gonna write the code in the way you recommend.

Thanks!
Venkat PolisettiVenkat Polisetti
@Soporte Ti,

As previously mentioned by other posters here, if you have a Visualforce page, they you can pre-populate fields. There are other hacks that you can implement but they all suffer from the same pit falls as they are all hacks. 

For instance, you could set up a home page component that uses JQuery and tracks your standard page and changes the dom elements to inject your own values so that it appears as if they are prepopulated. This is no better than the url hack in anyway as this is more complicated than using unpublished SF params to populate values.

Triggers fire after the DML occurs so they do not help you in this case. There is not standard event that fires before showing a page in SF. So your options are limited in this case. You can always go for a VF page, though.

Thanks,
Venkat