1

I'm looking to create a trigger that will populate a picklist field from the asset name. Like If asset name starts with X, then set value Y. I tried with field updates but it won't fire until i save the record, and i need it to fire at the creation of the record (when i click on ''new case'')

the reason why i need a picklist auto populated is because i need it to control another picklist, and it won't work with a formula field.

can anyone help?

thanks!

-Gabriel H

  • So you want to pre-populate the field? If this is the case a trigger will not help as the trigger wont fire until a DML action. It's not supported, but often people use URL hacking to pre-populate fields on standard pages – Chris Duncombe Sep 19 '13 at 14:33
  • i'm gonna have to go either controlling picklist or record types then, i just wanted to save my user one extra click. thank you! – Gab Silvermotion Sep 19 '13 at 14:43
  • Allright, i solved this with a button and url hacking to pass on parameters. was fun to learn and now i can use it everywhere! thanks! – Gab Silvermotion Sep 20 '13 at 19:19
  • @GabSilvermotion Could you write up your solution in a bit more detail, post it as the answer, then accept it in a couple of days? Really useful for the next person to Google this problem! – metadaddy Sep 20 '13 at 20:50
2

A trigger will not help here as a trigger will not fire until a DML action. In order to pre-populate a field you can (not supported) use URL hacking techniques. You could also use Visualforce, which would allow to have a default value for the field.

As you pointed out, Record Types would also be an option to ensure the correct pick list values are included for different types.

I suppose it comes down to your personal preference, but using triggers will not help in this situation.

  • I don't believe URL hacking will works in this case, as the value i'm trying to prepopulate is tied to a part of the asset name (the first 2 words of the asset name to be precise). i'll investigate visual force, i need to learn it anyways. thanks! – Gab Silvermotion Sep 19 '13 at 15:05
  • Yes, if the name is dependent on another field that is populated on the page, and you want it in real time, ie not after the record is saved, then you will need to look into Visualforce with some jQuery to update the field as the asset name is filled in. – Chris Duncombe Sep 19 '13 at 15:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.