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

help me with trigger

hi guys,


I have a relatd list called feed back on accounts and contacts.

My requirement is when ever a feedback is created it should display in the relatd opportunity also.

if a feedback is created from oppty it should visible in contact also.

please help me with a triigger.


Thanks in advance.




Saikishore Reddy AengareddySaikishore Reddy Aengareddy

can you explain little more about feed back object? Are you using task object or is it a custom object?


Hi sam_sfdc


My requirement is i have a custom object called feed back .which is having lookup of onto contact,oopportunity,payments.

when ever i have created a new efeedback  records  from contact object.

Then if the contact is having opportunity then these feedback sholud be appear in opportunity related list comments.

If attach a new feedback  in opportunity it should attach to related contact of opportunity as well as fpayments object.


Simply when ever u create a feedback from contact or opportunity or payments these comment should be appear in all the

objects related list.





Suppose Feedback is added to a Contact, then you need to find the opportunity to which this contact is related with. It can be done by querying OpportunityContactRole object. So you might use something like this,

List<OpportunityContactRole> listCRole = [Select ContactId,OpportunityId FROM OpportunityContactRole WHERE ContactId IN: Trigger.newMap.keySet()];


Then in 2 for loops (for(Feedback__c f : Trigger.New), and for(OpportunityContactRole ocr: listCRole)) you can iterate and check for the matching ContactId, once match found, just update the current record - i.e. here, f.Opportunity__c = ocr.OpportunityId.


Please note that you might require additional maps/sets/lists to handle records in bulk.

Hi can u help me in making this trigger as bulk trigger. trigger upcom on Comments__c(Before insert) { Comments__c f; for(Comments__c{ f=fs; } if(f.Opportunity__c!=null ){ for(Opportunity cm:[select id,Name,Borrower__c from opportunity where id=:f.opportunity__c ]){ f.Contact__c=cm.Borrower__c; } } } Thanks Frank