+ Start a Discussion
Nickolay IvanovichNickolay Ivanovich 

I need move data from List<Object1> to List<Object2>

Assign the fields of one object to another. and  update data of Project_c
like this
Best Answer chosen by Nickolay Ivanovich
GovindarajGovindaraj
This should work.
trigger Test on Estimate__c (after insert) {
 Set<Id> estimateIds = new Set<Id>();
 list<Project__c> updateProjList = new list<Project__c>();
    for (Estimate__c estimateObj : Trigger.new) {
        estimateIds.add(estimateObj.Id);        
            }

List<Estimate__c> lstEstimate = [SELECT Total_Hours__c, Total_Amount__c FROM Estimate__c WHERE Id IN : estimateIds];

	for(Estimate__c estimateObj : lstEstimate) {
		Project__c projObj = new Project__c();
		projObj.Estimated_Hours__c = estimateObj.Total_Hours__c;
		projObj.Estimates_Amount__c = estimateObj.Total_Amount__c;
		updateProjList.add(projObj);
	}
	Update updateProjList;
 }

All Answers

Nickolay IvanovichNickolay Ivanovich
How do this please help!!
Nickolay IvanovichNickolay Ivanovich
trigger Test on Project__c (after insert) {
    List<Project__c> ListWthPorj = [select id,Estimated_Hours__c,Estimated_Amount__c from Project__c
                                    where (Estimated_Hours__c = null and
                                    Estimated_Amount__c= null)];
    
    list<Estimates__c> ListWthEst = [select id,Total_Hours__c,Total_Amount__c from Estimates__c where Project__c in: Trigger.new];
    
    for(Project__c prj :ListWthPorj){
        
        prj.Estimated_Hours__c= //assigned Total_Hours__c from Estimates__c
        prj.Estimated_Amount__c=//assigned Total_Amount__c from Estimates__c
    }
    update ListWthPorj;
}
//MyCode

 
Nickolay IvanovichNickolay Ivanovich
Hi @Govindaraj,
Hi, I had a problem with the concept of task, i need use trigger on Estimate__c (after insert), What's changing in your code? (I apologize for the false information)
 
Nickolay IvanovichNickolay Ivanovich

I think it doesn't works cause we get data from projectObj and put to projObj i think it's should look like (for example) projObj.Estimated_Amount__c = EstimatedObj.Total_Hours__c;
projObj.Estimated_Hours__c= EstimatedObj.Total_Amount__c;
I am beginner and my questions can be stupid,
Thanks for help
Im  online

Nickolay IvanovichNickolay Ivanovich
@Govindaraj and projectIds does not exist
GovindarajGovindaraj
This should work.
trigger Test on Estimate__c (after insert) {
 Set<Id> estimateIds = new Set<Id>();
 list<Project__c> updateProjList = new list<Project__c>();
    for (Estimate__c estimateObj : Trigger.new) {
        estimateIds.add(estimateObj.Id);        
            }

List<Estimate__c> lstEstimate = [SELECT Total_Hours__c, Total_Amount__c FROM Estimate__c WHERE Id IN : estimateIds];

	for(Estimate__c estimateObj : lstEstimate) {
		Project__c projObj = new Project__c();
		projObj.Estimated_Hours__c = estimateObj.Total_Hours__c;
		projObj.Estimates_Amount__c = estimateObj.Total_Amount__c;
		updateProjList.add(projObj);
	}
	Update updateProjList;
 }
This was selected as the best answer
GovindarajGovindaraj
Hi,

Please keep this communtiy clean by closing solved cases.

Thanks,
Govindaraj.S