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
M V CHARANDEEPM V CHARANDEEP 

when a new high priority case is created on an account with reason as Breakdown the case information has to be posted on to the chatter box using triggers

The above is the scenario 
I want an answer for this
Best Answer chosen by M V CHARANDEEP
Sai PraveenSai Praveen (Salesforce Developers) 
Hi Charandeep.

Can you check the below trigger which will add body as subject of the case.
Can you confirm if we need to check reason on Account or Case?
trigger PostChatter on Case (after insert) {
   
     if(Trigger.isAfter && Trigger.isInsert){
         list<FeedItem> feedlist = new list<FeedItem>();
        for(Case cs : Trigger.new){
            if(cs.Priority == 'High'){
            FeedItem post = new FeedItem();
            post.ParentId = cs.Id;
            post.Body = cs.Subject;
            feedlist.add(post);
          
        }
         Insert feedlist;
       } 
     }
    }

Let me know if you face any issues.

If this solution helps, Please mark it as best answer.

Thanks,

All Answers

Sai PraveenSai Praveen (Salesforce Developers) 
Hi Charandeep,

What information you need to post in chatter. You need information related to specific fields?

Thanks,
 
Vineela ProddaturuVineela Proddaturu
Hi Charandeep
May be, it will help you.
trigger casetrigger on Case (after insert) {
     if(Trigger.isAfter && Trigger.isInsert){
         list<FeedItem> lstFI = new list<FeedItem>();
        for(Case cc : Trigger.new){
            FeedItem post = new FeedItem();
            post.ParentId = cc.Id;
            post.Body = 'BreakDown the case information';
            lstFI.add(post);
          
        }
         Insert lstFI;
       } 
    }

If it helps,mark as best answer
 
M V CHARANDEEPM V CHARANDEEP
Hi Sai Praveen I want to post that new priority case which has been created ,no specific field are required
M V CHARANDEEPM V CHARANDEEP
Hi Vineela It is working but I want it to happen when my conditions are met, not every time.
Vineela ProddaturuVineela Proddaturu
Hi Charandeep
trigger casetrigger on Case (after insert) {
    if(Trigger.isAfter && Trigger.isInsert){
        list<FeedItem> lstFI = new list<FeedItem>();
        for(Case cc : Trigger.new){
            if(cc.Priority == 'High'){
                FeedItem post = new FeedItem();
                post.ParentId = cc.Id;
                post.Body = 'BreakDown the case information';
                lstFI.add(post);
            }
        }
        Insert lstFI;
       } 
    }
Whenever case is created & priority is high, then only it will fire the trigger.
    
    
 
Sai PraveenSai Praveen (Salesforce Developers) 
Hi Charandeep.

Can you check the below trigger which will add body as subject of the case.
Can you confirm if we need to check reason on Account or Case?
trigger PostChatter on Case (after insert) {
   
     if(Trigger.isAfter && Trigger.isInsert){
         list<FeedItem> feedlist = new list<FeedItem>();
        for(Case cs : Trigger.new){
            if(cs.Priority == 'High'){
            FeedItem post = new FeedItem();
            post.ParentId = cs.Id;
            post.Body = cs.Subject;
            feedlist.add(post);
          
        }
         Insert feedlist;
       } 
     }
    }

Let me know if you face any issues.

If this solution helps, Please mark it as best answer.

Thanks,
This was selected as the best answer
Vineela ProddaturuVineela Proddaturu
Hi Charandeep
 if(cc.Priority == 'High' && cc.Reason == 'Breakdown')
Pls,add case reason also,i forgot about case reason. I am sorry about this one.Now,it works your conditions are met, not every time.

Pls, mark it as best answer.
 
M V CHARANDEEPM V CHARANDEEP
Hi It worked and Thank you for your help. I'll mark it as the best answer.
M V CHARANDEEPM V CHARANDEEP
This also worked out,will mark it as the best answer. Thank you
M V CHARANDEEPM V CHARANDEEP
@sai Praveen and @Vineela.

Your codes has worked out to me but there are three conditions here  if(Cc.Priority=='High'&&Cc.Status=='New'&& cc.Reason=='BreakDown' if(Cc.Priority=='High'&&Cc.Status=='New'&& cc.Reason=='BreakDown')