You need to sign in to do that
Don't have an account?
kirankumarreddy punuru 10
How to copy data from a standard object to a custom object
Hi ,
I am trying to copy data from a standard object to a custom object through trigger and i have written one trigger for this please help in this trigger wheather this is correct or i need to change .My trigger is:
trigger chatterComments on FeedComment (after insert)
{ List<FeedComment__c> customObj = new List<FeedComment__c>();
List<FeedComment> standardObj = new List<FeedComment>();
lststandardObj =[Select id,CommentBodyfrom FeedComment];
for(FeedComment fc:lststandardObj){
FeedComment__c fc1 = new FeedComment__c();
fc1.CommentBody__c = lststandardObj.CommentBody;
customObj.add(fc1);
}
if(customObj.size()>0){
insert customObj;
}
}
I am trying to copy data from a standard object to a custom object through trigger and i have written one trigger for this please help in this trigger wheather this is correct or i need to change .My trigger is:
trigger chatterComments on FeedComment (after insert)
{ List<FeedComment__c> customObj = new List<FeedComment__c>();
List<FeedComment> standardObj = new List<FeedComment>();
lststandardObj =[Select id,CommentBodyfrom FeedComment];
for(FeedComment fc:lststandardObj){
FeedComment__c fc1 = new FeedComment__c();
fc1.CommentBody__c = lststandardObj.CommentBody;
customObj.add(fc1);
}
if(customObj.size()>0){
insert customObj;
}
}
If that's the case, then remove the lstandardobjec =[Select .... line. Chang the for loop to this...
for(FeedComment fc :trigger.new) {
Thanks for your comment , yes i need to copy standard object data to a custom object that' s it for that no need to write query ?
Is this is correct
trigger ChatterTrigger on FeedComment (after insert) {
{ List<FeedComment__c> customObj = new List<FeedComment__c>();
for(FeedComment fc:Trigger.new){
FeedComment__c fc1 = new FeedComment__c();
fc1.Body__c = fc.CommentBody;
customObj.add(fc1);
}
if(customObj.size()>0){
insert customObj;
}
}
}