You need to sign in to do that
Don't have an account?
Mohini
how to dynamically search a picklist values
There is a picklist field Prod Type in child object ,sub opportunity . Based on similar Prod Type values the child object sub opportunity's field "revenue" should get averaged and for differnt product types values the child object "Sub opportunity " revenue field should be sumed at the parent object that is opportunity.
Please help me to achive this in my trigger
trigger RolllupSubAmt on Sub_Opportunity__c ( after insert, after update,after delete,after undelete) {
Set<Id> oppIdSet=new Set<Id>();
List<Opportunity> opptyListToUpdate=new List<Opportunity>();
if(Trigger.isInsert || Trigger.isUpdate || Trigger.isUndelete){
for(Sub_Opportunity__c subopp : Trigger.new){
if(subopp.Opportunity__c!= null){
oppIdSet.add(subopp.Opportunity__c);
}
}
}
If(Trigger.isDelete){
for(Sub_Opportunity__c opp : Trigger.old){
if(opp.Opportunity__c!= null){
oppIdSet.add(opp.Opportunity__c);
}
}
}
for(AggregateResult res : [SELECT Opportunity__c,avg(Actual_Revenue_Rollup__c)can FROM Sub_Opportunity__c WHERE Opportunity__c IN :oppIdSet GROUP BY Opportunity__c ]) {
opptyListToUpdate.add(new Opportunity(Id=(Id)res.get('Opportunity__c'), Actual_Revenue2__c=(Double)res.get('can')));
}
try{
update opptyListToUpdate;
}catch(DmlException de){
System.debug(de);
}
}
Please help me to achive this in my trigger
trigger RolllupSubAmt on Sub_Opportunity__c ( after insert, after update,after delete,after undelete) {
Set<Id> oppIdSet=new Set<Id>();
List<Opportunity> opptyListToUpdate=new List<Opportunity>();
if(Trigger.isInsert || Trigger.isUpdate || Trigger.isUndelete){
for(Sub_Opportunity__c subopp : Trigger.new){
if(subopp.Opportunity__c!= null){
oppIdSet.add(subopp.Opportunity__c);
}
}
}
If(Trigger.isDelete){
for(Sub_Opportunity__c opp : Trigger.old){
if(opp.Opportunity__c!= null){
oppIdSet.add(opp.Opportunity__c);
}
}
}
for(AggregateResult res : [SELECT Opportunity__c,avg(Actual_Revenue_Rollup__c)can FROM Sub_Opportunity__c WHERE Opportunity__c IN :oppIdSet GROUP BY Opportunity__c ]) {
opptyListToUpdate.add(new Opportunity(Id=(Id)res.get('Opportunity__c'), Actual_Revenue2__c=(Double)res.get('can')));
}
try{
update opptyListToUpdate;
}catch(DmlException de){
System.debug(de);
}
}