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
VishyVishy 

Trigger to update actual completion date from Opportunity field to field in Plot object

Hi sorry if this is in the wrong place but i am struggling to create a trigger that will automaticially add the date entered in Actual_Completion_Date__c on the Opportunity object to one (Actual_Completion_Date__c) in the plot object. I have created a look up field in the plot object called Opportunity_Link as i was unable to fill the date field using formulas and different field types.
sunil316sunil316

Hello, I think this should work for you,

 

 

trigger insertDate on Plot__c (before insert) 

{

Set<id> objSet = new Set<id>();

for(Plot__c objPlot: Trigger.new)

{

objSet.add(objPlot.Opportunity_Link__c);

}

List<Opportunity> lstOpp = [select id, Actual_Completion_Date__c from Opportunity where Id in: objSet];

for(Plot__c objPlot: Trigger.new)

{

for(Opportunity objOpp: lstOpp)

{

if(objPlot.Opportunity_Link__c == objOpp.Id)

{

objPlot.Actual_Completion_Date__c = objOpp.Actual_Completion_Date__c;

}

}

}

 

 

 

 -Sunil 

VishyVishy

Hi Sunil thanks for your reply. I am getting this error when i try to save the trigger:

 

Error: Compile Error: Incorrect SObject type: Plot__c should be Opportunity at line 1 column 1 

 

Any ideas?

sunil316sunil316

You have to right trigger on your custom object not on opportunity. I am taking it as Plot__c. Write trigger on, whatever your custom object name is.

 

This is the only problem, trigger is working fine.

 

 

- Sunil