0

My setup:

Every month I have a .NET app that uploads data into a custom object (ChurchHist__c) that keeps track of each church's contributions for that month. There are little over 2,200 records inserted per month.

What I need to do:

Once these records are inserted into the object I need to check the new "ContribForMonth" data against last month's data. If there is a drop of a certain percentage, email a customer service rep so s/he can contact the church and try to help with any issues.

What I'm thinking:

Create a trigger (before insert) that gets last month's data and compare it to the new data coming in. So:

1.) Store last month data in a Map list. 2.) Loop through the new data in Trigger.new and find corresponding data in the map. 3.) Compare the two values. 4.) Email account owner

Does this seem like a good way to do this or is there a simpler way? I'm still learning my way around SF so any advice would be helpful.

  • Is there a "Church" object that is the parent of all these ChurchHist__c objects? – Simon Lawrence Feb 14 '14 at 15:13
  • 1
    I would say thats probably the best way to do it. The hardest part is determining the best way to get last months data. – dphil Feb 14 '14 at 15:17
  • @SimonLawrence Account is the parent of ChurchHist__c. – Randy R Feb 14 '14 at 15:23
  • @dphil My ChurchHist__c object stored the "Month end date" as a field so getting last months data is easy. MonthEndDate__c was added so I could order the records to display apex charts on another project :) – Randy R Feb 14 '14 at 15:26
  • 1
    Your idea should work sufficiently to accomplish your goal then. – dphil Feb 14 '14 at 15:28
1

How about using Analytic Snapshot functionality of Salesforce? This is what it is supposed to be used for - to identify patterns at regular intervals.

https://help.salesforce.com/HTViewHelpDoc?id=data_setting_up_analytic_snap.htm&language=en_US

Based on the snapshot data you could schedule reports/dashboards and mail it to your users.

| improve this answer | |
0

The easiest way to aggregate data like this would be in a roll up summary field

You can do this in your account object as a new custom field, and roll up the totals of the ChurchHist__c "values" (whatever field the contribution goes into)

rollup

Use the filter fields to just grab the records you want. I was just typing up a cool way to do this using a formula field containing something along the lines of

MONTH(DATEVALUE(createdDate)) == MONTH(TODAY() - 1)

In your ChurchHist__c object, so it would be true when it was created in the last month, otherwise false. (you could then use a similar field to do this month). It seems you probably have a reasonable idea how you will catch the relevant records though? (if not, that should work).

With two roll up summaries on account for the last two months totals, you could then look to a bit of workflow to send the e-mail? You would want to find a way to update account when the loading had been completed (simple enough) and then on an Account Workflow rule, set up a condition like this:

workflow

And then have a Workflow immediate action for an Email alert, chuck in a template, and it should all work for you (DON'T forget, activate workflow rules when you have finished them... ultimate gotcha!)

| improve this answer | |
  • 1
    Ah, is there one ChurchHist__c object per Account per month? With the "2,200" fact, I assumed there were many per account and you needed to know how the totals compare? If there is just one amount per Account, you can disregard the "roll up summary" bit of the answer... – Simon Lawrence Feb 14 '14 at 15:56
  • Yes, ChurchHist__c contains ONE record PER church PER month. Basically a monthly summary of each of our customers. – Randy R Feb 14 '14 at 18:36
  • Thanks for your help though, I got the trigger working fairly easy. I've never did a Rollup yet so will keep this post in mind :) – Randy R Feb 15 '14 at 1:02
  • 1
    No worries :) did you explore the possibility of using workflow? With a formula/criteria a little bit like my screenshots above as well? The best thing about using formula fields and workflow is, zero test coverage! Can also be promoted/maintained between orgs much easier with no code requirements. Hope you continue to enjoy discovering force.com :) – Simon Lawrence Feb 15 '14 at 9:44

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.