+ Start a Discussion
pujapuja 

Chatter posts for Open Opportunities

      

Can anyone help me for implementing this requirement .    

  • Search all Chatter posts for Open Opportunities and identify the most recent that contains “#nextstep”.
  • If a Chatter post is found, strip out the text of that post and update the Opportunity Next Step field with the Chatter text.

 

It's urgent ....i have tried this but i have not understood what is the meaning for text of that Chatter post

 

 

 

Please help...

 

Thanks in advanced

Best Answer chosen by Admin (Salesforce Developers) 
RajivRajiv

Hi Puja,

 

You can use below code:

 

trigger chatterpost on FeedItem (after insert) {

List<Id> feeditemIds = new List<Id>();
for(FeedItem f: Trigger.New){
    feeditemIds.add(f.parentId);
    system.debug('f.Id'+f.parentId);
}

List<opportunityFeed> oppChatterValue = [Select body,Id,parentId from opportunityFeed where parentId IN: feeditemids order by CreatedDate DESC limit 1];
List<Id> oppId = new List<Id>();
Map<Id,opportunity> oppMap = new Map<Id,opportunity>([Select Id from opportunity where Id IN: feeditemIds]);

List<opportunity> oppInsert = new List<opportunity>();
Set<opportunity> oppInsertSet = new Set<opportunity>();
for(integer i=0; i<oppChatterValue.size(); i++){
    opportunity oppObject = oppMap.get(oppChatterValue[i].ParentId);
    oppObject.NextStep = oppChatterValue[i].body;
    oppinsertSet.add(oppObject);   
}   
    oppinsert.addAll(oppinsertSet);
   
    if(oppinsert.size() > 0)
        upsert oppinsert;

}

 

 

 

if it works please mark as a solution.

 

Thanks,

All Answers

Niket SFNiket SF

Hello Pooja,

It's possible to find the "Chatter Post" because for Chatter Post are two type's 1. Is for User level   2. Is for Record level. 

 

              with the help of the "ItemFeed" object you need to find that recrent post. and then you need to get that post string and update in to the Opportunity Next field.

 

So indirectly you need to write a trigger on the Chatter Post when chatter is get post on the Opportunity record update the Next Step on the respective record.

 

 

Thanks 

Nik's

 

Skype name : niket.chandane

 

 

 

 

RajivRajiv

Hi Puja,

 

You can use below code:

 

trigger chatterpost on FeedItem (after insert) {

List<Id> feeditemIds = new List<Id>();
for(FeedItem f: Trigger.New){
    feeditemIds.add(f.parentId);
    system.debug('f.Id'+f.parentId);
}

List<opportunityFeed> oppChatterValue = [Select body,Id,parentId from opportunityFeed where parentId IN: feeditemids order by CreatedDate DESC limit 1];
List<Id> oppId = new List<Id>();
Map<Id,opportunity> oppMap = new Map<Id,opportunity>([Select Id from opportunity where Id IN: feeditemIds]);

List<opportunity> oppInsert = new List<opportunity>();
Set<opportunity> oppInsertSet = new Set<opportunity>();
for(integer i=0; i<oppChatterValue.size(); i++){
    opportunity oppObject = oppMap.get(oppChatterValue[i].ParentId);
    oppObject.NextStep = oppChatterValue[i].body;
    oppinsertSet.add(oppObject);   
}   
    oppinsert.addAll(oppinsertSet);
   
    if(oppinsert.size() > 0)
        upsert oppinsert;

}

 

 

 

if it works please mark as a solution.

 

Thanks,

This was selected as the best answer
pujapuja

Hi Rajiv.

 

            I am trying on this but it's not working.

RajivRajiv

Can you please tell me the step ur following!!!!

pujapuja

First i have enable the Chatter feed for opportunity and after that i have clicked on the Button Follow button for following the Opportunity and then i have added this code on the FeedItem Trigger.

 

But when i edit the opportunity record this trigger is not fire ,i don't know why that is not fire ..please help me it's urgent.

 

 

 

 

 

 

 

Thanks

RajivRajiv

Hey puja.  this trigger will not  work on edit. You have to enter some feed(or post) on the box which is present at the top side off opportunity. After that you have to refresh the opportunity record. You will see whatever u entered on the chatter box it's now available to the nextStep field of opportunity.

 

Let me know if you have any more questions.

pujapuja

Hi Rajiv,

 

 

              then what is the meaning of

 

"Search all Chatter posts for Open Opportunities and identify the most recent that contains “#nextstep”."

 

 

Thanks

pujapuja

Hi Rajiv ,

      

      thanks...

 

 

This is work for me...