How to track more than 20 fields values in Salesforce?

How to track more than 20 fields values in Salesforce?

Write a tirgger and create a Chatter feed.

Sample Trigger:

trigger FieldHistory on Member__c (after insert, after update) {
    Map<Id, Member__c> MemberMap = trigger.oldMap;
    List<FeedItem> FIList = new List<FeedItem>();
    if(trigger.isInsert) {       
        for(Member__c Mem : trigger.new) {
            FeedItem FI = new FeedItem();
            FI.Body = ‘Member Created’;
            FI.ParentId = Mem.Id;
            FIList.add(FI);
        }
        insert FIList;
    }
    if(trigger.isUpdate) {
        for(Member__c Mem : trigger.new) {
            Member__c OldMem = new Member__c();
            OldMem = MemberMap.get(Mem.Id);
            if(Mem.Area__c != OldMem.Area__c) {
                FeedItem FI = new FeedItem();
                FI.Body = ‘Area changed from ‘ + OldMem.Area__c + ‘ to ‘ + Mem.Area__c;
                FI.ParentId = Mem.Id;
                FIList.add(FI);
            }
        }
        if(!FIList.isEmpty()){
            insert FIList;
        }       
    }
}

Output:


Leave a Reply