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
NewCoderBoyNewCoderBoy 

why do i get this error on a trigger i created

I wrote a trigger on a parent object to update the child object so an email alert does not get sent out.  the email alert is on a workflow rule attached to the child object called Lead Source.  any help you can provide would be appreciated.

the Parent object is Opportunity and I continue to get this error on line 15:

Illegal assignment from SOBJECT:Opportunity toSOBJECT:Lead_Source__C

here's the code:

trigger FieldVisitComplete on Opportunity (after insert, after update) {
 
    Set <Id> oppIds = new Set<Id>();
      
        for (Opportunity parentObj : Trigger.new)
        {
            oppIds.add(parentObj.Id);
    
        }
           Map<Id, Opportunity> parentObjList = new Map<Id, Opportunity>([Select Initial_Field_Visit_Completed__c FROM Opportunity WHERE ID IN :oppIds]);
               
               for (Opportunity opp : Trigger.new) {
                     
                   if (opp.Initial_Field_Visit_Completed__c != null) {
                       Lead_Source__c  lsrc  = parentObjList.get(opp.Id);
                       lsrc.Initial_Field_Visit__c = opp.Initial_Field_Visit_Completed__c;
                                
                   } 
               }
   
             {
                 update parentObjList;
             }
}
Ramu_SFDCRamu_SFDC
When you are initiating a variable as Lead_Source__c  lsrc  =  the variable expects a record of object Lead_Source__c. However in your current code you are assigning an Opportunity record to a Lead_Source__c record which is sytactically incorrect hence the error. To fix this, you have to change the code to

Opportunity Oppty = parentObjList.get(opp.Id); 
(or)
Lead_Source__c  lsrc  = //some lead source record.
NewCoderBoyNewCoderBoy
thank you!!