mishadoff
mishadoff

Reputation: 10789

Salesforce update master record when child objects updated

I have a program that pulls Salesforce Case objects, and their CaseComment and Solution objects. Also I have set of filters that allow me to reduce results (keywords, fromDate, toDate, etc.). The problem that I have is Salesforce functionality do not update neither Case LastModifiedDate nor SystemModstamp fields when I edit or create new comment for that Case.

The most straightforward solution to pull separately Cases, Comments and Solution then extract ParentId (CaseId) from Comments and Solutions, manually modify these CaseIDs with the max lastModifiedDate of Case or Solution and after that merge all Cases. But this process a bit routine, so I looking for another solution, both Salesforce and client sides.

Upvotes: 1

Views: 4678

Answers (2)

Born2BeMild
Born2BeMild

Reputation: 544

If you want to avoid using Triggers you can use Workflow to do the 'touching'. As of the Spring '12 release of salesforce.com cross-object workflow is supported. So you can create a workflow rule on the case comment that updates a field on the parent case. You could create a custom field specifically for this touching process or reuse any other field.

For example to use the Case Description field as the touched field you could do the following.

  1. Create a new workfow rule over the Case Comment object to fire whenever a record is created or edited.
  2. Specify the criteria for the workflow rule to be when the created date is not equal to null.
  3. Create a new workflow action for a field update.
  4. Specify that the object should be Case and the Field Description
  5. In the Formula enter Parent.Description as the value. This will set the Case Description to be its own value. Effectively making no change to the record.

With regards changing the LastModifiedDate or SysetemModstamp via the API I'm not sure that this is something you can do as part of an ongoing interface. Salesforce will allow you to update these audit fields via the API but you have to contact them to enable the functionality.

The salesforce online documentation covers the audit fields in more detail. It says:

If you import data into Salesforce and need to set the value for an audit field, contact salesforce.com. Once salesforce.com enables this capability for your organization, you can set audit field values for the following objects: Account, CampaignMember, Case, CaseComment, Contact, FeedComment, FeedItem, Idea, IdeaComment, Lead, Opportunity, and Vote. The only audit field you cannot set a value for is systemModstamp.

Upvotes: 4

JCD
JCD

Reputation: 2231

Simplest way I can think of is to just "touch" (update without making any modifications to the data) the Case record whenever a CaseComment is created or edited. This can be accomplished with a trigger on CaseComment:

trigger CaseCommentAIAU on CaseComment (after insert, after update) {
    Set<Id> caseIds = new Set<Id>();
    for ( CaseComment cc : Trigger.new ) {
        caseIds.add(cc.ParentId);
    }
    Case[] caseUpdates = [select id from Case where Id in :caseIds];
    update caseUpdates;
}

Upvotes: 3

Related Questions