function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
alemalem 

post an update to a chatter group when an account field has been changed.

Does anyone know if there is a workflow rule or trigger rule I can create to post an update (that includes multiple fields) to a chatter group when an account field has been changed?

 

Thank you

Sonam_SFDCSonam_SFDC

Hi Alem,

 

You can create a workflow on Account object to create a post on the group of your choice when the account record is update.

 

I have a sample code which I wrote to create a post on the same account:

 

Trigger:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
trigger chatterfeed on Account (after update) {

List <FeedItem> chatterPostsToAdd = new List <FeedItem>() ;

for(Account e : Trigger.new){
FeedItem accountPost = new FeedItem();
accountPost.ParentID = e.Id ;
accountPost.Body = 'updated account '; 

accountPost.LinkUrl = '/' + e.id ;
chatterPostsToAdd.add(accountPost);
}

System.debug(chatterPostsToAdd);
insert chatterPostsToAdd;

}

 

 

 

alemalem

Thank you. 

 

We tried using this code in our sandbox environment but received errors when trying to edit an account field.  Is there something we need to edit or customize  in your code?  

 

Is there really no other way to form a link between updating accounts and opportunities and posting in chatter?  It seems like a common request people would have.  

 

Alem

 

 

spatelcespatelce

Alem,

 

It would be really helpful for members to update a code where you received an error or errors in code by posting it in here.

 

So far, I can make a wild guess and here is a code that I had used to chatter group on change of fields in Opportunity object.

 

trigger ChatterWonOpty on Opportunity (after update) {
 
String status;
String OppAccName;
String OppOnrName;
FeedItem post = new FeedItem();
    
    if ( Trigger.isUpdate ) {
        if( o.IsWon == true && Trigger.oldMap.get(o.id).IsWon == false) { 
            for (Opportunity oppty : [SELECT Account.Name, Owner.Name FROM Opportunity WHERE Id =:o.Id] ) {
                OppAccName = oppty.Account.Name;
                OppOnrName = oppty.Owner.Name;
            }    
            status = OppOnrName + ' just won ' + OppAccName + ' for ' + o.Amount + '!';
                            
            post.ParentId = '0F9Z00000000DJW';
            post.Title = o.Name;
            post.Body = status;
                        
            insert post;      
        }
    }    
}

 

Hope it will help...

 

 

 

-Saw