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
Anil MeghnathiAnil Meghnathi 

Record is not getting inserted in new Object in FeedItem trigger

I have a sobject TestStoring__c with one custom field Body__c.In after insert trigger on FeedItem ,  when i insert a record in 

TestStoring__c sobject,it is not getting inserted.I am also attaching the code below.

 

Trigger:

 

trigger Test on FeedItem (after insert) 
{
FeedItem[] f=Trigger.New;
TestTriggerClass.addFeedError(f);

System.debug(TestTriggerClass.flag);
if(TestTriggerClass.flag!='done')
{
TestStoring__c vv=new TestStoring__c();
vv.Body__c=f[0].body;
insert vv;
}
}

 

 

Class:

 

public class TestTriggerClass
{
public static string flag;
public static void addFeedError(list<FeedItem> fi)
{
if(fi[0].body.contains('blocked'))
{
flag='not';
fi[0].adderror('Not Allowed');
return;
}
else
{
flag='done';
return;
}
}
}

 

 

If you have any solution please help me?Its urgent.please

 

Thanks

Anil Meghnathi

Anu Raj.ax1269Anu Raj.ax1269

Hi 

  Try this code :

   

trigger Test on FeedItem (after insert) 

{


for(FeedItem fd : trigger.new){

 

if(fd.flag!='done'){

TestStoring__c vv=new TestStoring__c();
vv.Body__c=f[0].body;
insert vv;
}


}

crop1645crop1645

don't forget to bulkify it

 

trigger Test on FeedItem (after insert) {
   List<Test_Storing__c> tsList = new List<Test_Storing__c>();
   for(FeedItem fd : trigger.new){
      if(fd.flag!='done')
         tsList.add(new Test_Storing__c (body__c = fd.body));        
   }
   insert tsList;

}

 

Anil MeghnathiAnil Meghnathi

Sorry crop 1645

 

 

Following error is comming.

 

Invalid field flag for SObject FeeItem

 

Any other idea?

 

Anil