+ Start a Discussion
Yogesh BiyaniYogesh Biyani 

One time update to contact fields

Hello, 
We create a case to track purchases. I would like to update contact fields such as date first purchased, date last purchased, first license #, last license # etc. using the information from the case. How would I go about it? I am new to SOQL but I think something like this may work.

1) Get all the contacts with the purchases
2) For each contact 
  1. Get all the cases for purchases 
  2. Use Min (Created Date) and Max(Created Date) for first and last purchases
  3. Find the License info for case with Min (Created Date) and Max(Created Date)
  4. Set the values on the contact fields
3) Update the list of  contacts 

After the one time update, I plan to use triggers for future purchases.

Thanks in advance.

Regards,
Yogesh
 
J DoveJ Dove
For first purchases, you could set the the Min(Created Date) and License # on before insert. Then for each subsequent purchase, you just update the Max(Created Date) and the License #. You could use a single after insert trigger and a couple trigger handler methods.
Yogesh BiyaniYogesh Biyani
@J Dove, Thanks for the trigger suggestions. However, I have quite a few contacts with purchases which I need to update first. 

Yogesh