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
Cameron BumsteadCameron Bumstead 

Checkbox marked true after attachment is attached on opportunity


I want a checkbox to be marked true after a contract/document is attached to a standard opportunity record. I want the field called "Contract_Attached__c" to be marked true once something is attached to the opportunity. I will make the field read-only so they cannot manually mark the field true. Let me know if someone can help!
You need to write a trigger on Attachment object and then query the opportunity record using the ParentId field on Attachment and update the checkbox. Try this
trigger UpdateCheckbox on Attachment (after insert)
	Set<Id> setOpportunityId = new Set<Id>();
	List<Opportunity> lstOpp = new List<Opportunity>();
	for(Attachment att:{
	for(Opportunity opp: [Select Id, Contract_Attached__c from opportunity where Id IN:setOpportunityId]){
		opp.Contract_Attached__c = True;
		update lstOpp;