You need to sign in to do that
Don't have an account?
Girbson Bijou 8
Illegal assignment from List to Map
I want want to update child in a self lookup relationship with value of the parent. The idea is to create a child with projectType ='Sanitition' when a record is created with the type of House. And update the child anytime the parent is updated. The error msg i get is: Illegal assignment from List<Output__c> to Map<Id,Output__c> at the line 29
trigger AutoOutput on Output__c (after insert, after update) { If(Trigger.isInsert){ List<Output__c> lstNewOutputs = new List<Output__c>(); for (Output__c NewOut : Trigger.New) { if ( NewOut.Project_Type__c =='House') { Output__c OutputChild = new Output__c(); OutputChild.Housing_If_Sanitation__c= NewOut.Id; OutputChild.Project_Type__c = 'Sanitition'; OutputChild.RecordTypeId=NewOut.RecordTypeId; OutputChild.Description__c=NewOut.Description__c; OutputChild.Locality__c=NewOut.Locality__c; OutputChild.Milestone__c= NewOut.Milestone__c; OutputChild.Address__c = NewOut.Address__c; OutputChild.claust__c=NewOut.claust__c; OutputChild.A__c=NewOut.A__c; OutputChild.Besem__c = NewOut.Besem__c; lstNewOutputs.add(OutputChild); } } if(!lstNewOutputs.isEmpty()) INSERT lstNewOutputs; } If(Trigger.isUpdate){ Map<Id,Output__c> outputsWithChilds = new Map<Id,Output__c>(); List<Output__c> lstNewOutputs = new List<Output__c>(); outputsWithChilds = [SELECT Id,(SELECT Id FROM Housing_If_Sanitation__r WHERE Project_Type__c = 'Sanitition')FROM Output__c WHERE Id IN :Trigger.New]; for (Output__c NewOut : Trigger.New) { if (NewOut.Project_Type__c =='House') { Output__c OutputChild = new Output__c(); OutputChild.Housing_If_Sanitation__c= NewOut.Id; OutputChild.Project_Type__c = 'Sanitition'; OutputChild.RecordTypeId=NewOut.RecordTypeId; OutputChild.Description__c=NewOut.Description__c; OutputChild.Locality__c=NewOut.Locality__c; OutputChild.Milestone__c= NewOut.Milestone__c; OutputChild.Address__c = NewOut.Address__c; OutputChild.claust__c=NewOut.claust__c; OutputChild.A__c=NewOut.A__c; OutputChild.Besem__c = NewOut.Besem__c; if(!outputsWithChilds.get(NewOut.Id).Housing_If_Sanitation__r.isEmpty()){ OutputChild.Id = outputsWithChilds.get(NewOut.Id).Housing_If_Sanitation__r[0].Id; } lstNewOutputs.add(OutputChild); } } if(!lstNewOutputs.isEmpty()) UPSERT lstNewOutputs; } }
All Answers