You need to sign in to do that
Don't have an account?
aparna d 1
populates values from parent to child
I have a requirement while inserting and updating of information records ,fetch values from opportunity and populate on Information object . opportunity is a lookup field on Information object.I have tried below code using triggers. please tell me where did i mistake.Its very urgent. Thanks in advance.
public static void TMOppCompInfo(List<Competitive_Infomation__c> complst)
{
List<Infomation__c> lstcompinfo = new List<Infomation__c>();
set<id> oppid = new set<id>();
Id TMoppRecord = Schema.SobjectType.Opportunity.getRecordTypeInfosByName().get('machinery').getRecordTypeId();
Id CloseOut = Schema.SobjectType.Competitive_Infomation__c.getRecordTypeInfosByName().get(' Information - Close Out').getRecordTypeId();
for(Competitive_Infomation__c comp : complst)
{
oppid.add(comp.Sub_Opportunity_Name__c);
}
List<opportunity> lstoppcomp = [select id,Emissions_Unit__c,Emissions_Guaranteed__c,Reason_for_Guarantee__c,Guaranteed_NOx_15_O2_ppm__c,Liquid_NOx_15_O2_ppm__c,
Guaranteed_CO_15_O2_ppm__c,Liquid_CO_15_O2_ppm__c,CBR_Temperature_Range_Unit__c,Temperature_Range__c,
Load_Range_pct__c,CBR_Engine_Emissions_Controls__c from opportunity where id =: oppid and recordType.Name = 'machinery' ];
IF(lstoppcomp.size()>0)
{
for(Competitive_Infomation__c compinfo : complst)
{
if(compinfo.Emissions_Same_as_Solar__c == 'same' && compinfo.RecordTypeId == CloseOut)
{
for(opportunity opplst : lstoppcomp)
{
compinfo.NOx_Emissions_15_O2__c = opplst.Guaranteed_NOx_15_O2_ppm__c;
compinfo.CO_Emissions_15_O2__c = opplst.Guaranteed_CO_15_O2_ppm__c;
compinfo.Liquid_NOx_Emissions_15_O2__c = opplst.Liquid_NOx_15_O2_ppm__c;
}
}
}
public static void TMOppCompInfo(List<Competitive_Infomation__c> complst)
{
List<Infomation__c> lstcompinfo = new List<Infomation__c>();
set<id> oppid = new set<id>();
Id TMoppRecord = Schema.SobjectType.Opportunity.getRecordTypeInfosByName().get('machinery').getRecordTypeId();
Id CloseOut = Schema.SobjectType.Competitive_Infomation__c.getRecordTypeInfosByName().get(' Information - Close Out').getRecordTypeId();
for(Competitive_Infomation__c comp : complst)
{
oppid.add(comp.Sub_Opportunity_Name__c);
}
List<opportunity> lstoppcomp = [select id,Emissions_Unit__c,Emissions_Guaranteed__c,Reason_for_Guarantee__c,Guaranteed_NOx_15_O2_ppm__c,Liquid_NOx_15_O2_ppm__c,
Guaranteed_CO_15_O2_ppm__c,Liquid_CO_15_O2_ppm__c,CBR_Temperature_Range_Unit__c,Temperature_Range__c,
Load_Range_pct__c,CBR_Engine_Emissions_Controls__c from opportunity where id =: oppid and recordType.Name = 'machinery' ];
IF(lstoppcomp.size()>0)
{
for(Competitive_Infomation__c compinfo : complst)
{
if(compinfo.Emissions_Same_as_Solar__c == 'same' && compinfo.RecordTypeId == CloseOut)
{
for(opportunity opplst : lstoppcomp)
{
compinfo.NOx_Emissions_15_O2__c = opplst.Guaranteed_NOx_15_O2_ppm__c;
compinfo.CO_Emissions_15_O2__c = opplst.Guaranteed_CO_15_O2_ppm__c;
compinfo.Liquid_NOx_Emissions_15_O2__c = opplst.Liquid_NOx_15_O2_ppm__c;
}
}
}
public static void TMOppCompInfo(List<Competitive_Infomation__c> complst)
{
List<Infomation__c> lstcompinfo = new List<Infomation__c>();
set<id> oppid = new set<id>();
Id TMoppRecord = Schema.SobjectType.Opportunity.getRecordTypeInfosByName().get('machinery').getRecordTypeId();
Id CloseOut = Schema.SobjectType.Competitive_Infomation__c.getRecordTypeInfosByName().get(' Information - Close Out').getRecordTypeId();
for(Competitive_Infomation__c comp : complst)
{
oppid.add(comp.Sub_Opportunity_Name__c);
}
Map<Id,opportunity> mapOppcomp = new Map<Id, Opportunity> ([select id,Emissions_Unit__c,Emissions_Guaranteed__c,Reason_for_Guarantee__c,Guaranteed_NOx_15_O2_ppm__c,Liquid_NOx_15_O2_ppm__c,
Guaranteed_CO_15_O2_ppm__c,Liquid_CO_15_O2_ppm__c,CBR_Temperature_Range_Unit__c,Temperature_Range__c,
Load_Range_pct__c,CBR_Engine_Emissions_Controls__c from opportunity where id =: oppid and recordType.Name = 'machinery' ]);
IF(mapOppcomp.size()>0)
{
for(Competitive_Infomation__c compinfo : complst)
{
if(compinfo.Emissions_Same_as_Solar__c == 'same' && compinfo.RecordTypeId == CloseOut)
{
Opportunity temp = mapOppcomp.get(compinfo.Sub_Opportunity_Name__c);
compinfo.NOx_Emissions_15_O2__c = temp.Guaranteed_NOx_15_O2_ppm__c;
compinfo.CO_Emissions_15_O2__c = temp.Guaranteed_CO_15_O2_ppm__c;
compinfo.Liquid_NOx_Emissions_15_O2__c = temp.Liquid_NOx_15_O2_ppm__c;
}
}
}
Thanks :)
All Answers
public static void TMOppCompInfo(List<Competitive_Infomation__c> complst)
{
List<Infomation__c> lstcompinfo = new List<Infomation__c>();
set<id> oppid = new set<id>();
Id TMoppRecord = Schema.SobjectType.Opportunity.getRecordTypeInfosByName().get('machinery').getRecordTypeId();
Id CloseOut = Schema.SobjectType.Competitive_Infomation__c.getRecordTypeInfosByName().get(' Information - Close Out').getRecordTypeId();
for(Competitive_Infomation__c comp : complst)
{
oppid.add(comp.Sub_Opportunity_Name__c);
}
Map<Id,opportunity> mapOppcomp = new Map<Id, Opportunity> ([select id,Emissions_Unit__c,Emissions_Guaranteed__c,Reason_for_Guarantee__c,Guaranteed_NOx_15_O2_ppm__c,Liquid_NOx_15_O2_ppm__c,
Guaranteed_CO_15_O2_ppm__c,Liquid_CO_15_O2_ppm__c,CBR_Temperature_Range_Unit__c,Temperature_Range__c,
Load_Range_pct__c,CBR_Engine_Emissions_Controls__c from opportunity where id =: oppid and recordType.Name = 'machinery' ]);
IF(mapOppcomp.size()>0)
{
for(Competitive_Infomation__c compinfo : complst)
{
if(compinfo.Emissions_Same_as_Solar__c == 'same' && compinfo.RecordTypeId == CloseOut)
{
Opportunity temp = mapOppcomp.get(compinfo.Sub_Opportunity_Name__c);
compinfo.NOx_Emissions_15_O2__c = temp.Guaranteed_NOx_15_O2_ppm__c;
compinfo.CO_Emissions_15_O2__c = temp.Guaranteed_CO_15_O2_ppm__c;
compinfo.Liquid_NOx_Emissions_15_O2__c = temp.Liquid_NOx_15_O2_ppm__c;
}
}
}
Thanks :)
Thanks a lot . Its working fine thank you!