1

In CS object, there is a field Quantity that is subject to be changed. The requirement is to store the initial value of that field in a separate custom field. 2 options are there :

  1. inlude in before insert trigger to populate this field . (this trigger is restricted and cannot be changed further)
  2. Create a workflow field update

Any other better way to do this? plesae advise.

4
  • 1
    u can enable history tracking for the field and then you can see all the value changes to that field including the initial value. Commented Jul 6, 2015 at 12:25
  • yes that is also there but still want to store the initial quantity in the same object itself (for reporting purpose etc)
    – user59759
    Commented Jul 6, 2015 at 12:33
  • 1
    Is this quantity field required when a new record is inserted? If not, you don't want to use a before insert trigger. If it is required, are there multiple fields/lines like in OLI on an Opp? If so, then I'd recommend a before insert trigger just to avoid the hassle of all the workflow involved.
    – crmprogdev
    Commented Jul 6, 2015 at 13:06
  • yes crmprogdev, i need to populate the initial quantity field value only at the time of record insertion, if quantity is getting changed next time, it will reamin same all the time. Also i cannot change the existing before update trigger and will have to create a 2nd one
    – user59759
    Commented Jul 6, 2015 at 13:11

3 Answers 3

2

You can use something like this in your trigger :

object_Name objOld = trigger.old[0];
for(object obj : trigger.new){
    obj.New_custom__c = string.valueOf(objOld.get(Quantity));
}

Let me know if this helps.

2

Workflow plus field update will work just fine. Create a rule that checks if Quantity is filled in and your custom field is blank. If this is the case, just copy the value.

2

From your description of this requiring a new beforeInsert trigger when you already have one in place that you can't modify, I'd recommend using workflow to populate the value to the related field when the record is created and only when it's created. Having more than one beforeInsert trigger, IMO isn't a good thing to do.

If you could consolidate the functionality into a single trigger, then that would be a worthwhile option to consider, but as you can't, workflow is definitely the way to go.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .