You need to sign in to do that
Don't have an account?
Dolgoldy
child record not inserting
Hi all,
My requirement is when opportunity is closed won and product family is 'recurring' then 12 child record shouls be inserted according to closed date. here is my code which is not inserted record.
////code
trigger ArrOpptrigger3 on Opportunity (after insert,after update) {
if(trigger.isInsert||trigger.isAfter){
//list<opportunityLineItem> olilist= new list<OpportunityLineItem>();
list<ARRCalcualateOpportunity__c> Arropplist= new list<ARRCalcualateOpportunity__c>();
// List<PriceBookEntry> priceBookList = [SELECT Id, Product2Id, Product2.Id, Product2.Name,product2.family
//FROM PriceBookEntry WHERE Product2.Family ='software Recurring' LIMIT 1];
//OpportunityLineItem oli= New OpportunityLineItem();
for(opportunity op:Trigger.New){
if(Op.StageName == 'closed Won')
{
for(OpportunityLineItem Oli:[select Id,Name,Product2Id,Product2.Family from
OpportunityLineItem where OpportunityId=:op.Id])
{
if(oli.product2.family == 'software Recurring__c')
{
ARRCalcualateOpportunity__c arrOpp = new ARRCalcualateOpportunity__c();
// arropp.Id = op.ID;
arropp.name = op.Name;
// arropp.OppArrAccount__c = op.AccountId;
arropp.ownerId = op.OwnerId;
arropp.OpportunityArr__c=op.Id;
Arropplist.add(arropp);
}
}
//if(olilist!=null&&olilist.size()>0)
}
}
insert Arropplist;
}
}
My requirement is when opportunity is closed won and product family is 'recurring' then 12 child record shouls be inserted according to closed date. here is my code which is not inserted record.
////code
trigger ArrOpptrigger3 on Opportunity (after insert,after update) {
if(trigger.isInsert||trigger.isAfter){
//list<opportunityLineItem> olilist= new list<OpportunityLineItem>();
list<ARRCalcualateOpportunity__c> Arropplist= new list<ARRCalcualateOpportunity__c>();
// List<PriceBookEntry> priceBookList = [SELECT Id, Product2Id, Product2.Id, Product2.Name,product2.family
//FROM PriceBookEntry WHERE Product2.Family ='software Recurring' LIMIT 1];
//OpportunityLineItem oli= New OpportunityLineItem();
for(opportunity op:Trigger.New){
if(Op.StageName == 'closed Won')
{
for(OpportunityLineItem Oli:[select Id,Name,Product2Id,Product2.Family from
OpportunityLineItem where OpportunityId=:op.Id])
{
if(oli.product2.family == 'software Recurring__c')
{
ARRCalcualateOpportunity__c arrOpp = new ARRCalcualateOpportunity__c();
// arropp.Id = op.ID;
arropp.name = op.Name;
// arropp.OppArrAccount__c = op.AccountId;
arropp.ownerId = op.OwnerId;
arropp.OpportunityArr__c=op.Id;
Arropplist.add(arropp);
}
}
//if(olilist!=null&&olilist.size()>0)
}
}
insert Arropplist;
}
}
Please use below code:-
if you need any assistanse, Please let me know!!
Kindly mark my solution as the best answer if it helps you.
Thanks
Mukesh
Make sure you are using the API Name for both the Stage and Family picklist fields, for instance, use Closed Won instead close won, sometimes the label and value are different, and I would suggest double check the same with the software Recurring__c picklist option.
Hope it helps.
I would suggest adding a few log statements to really see what value each variable has. for instance, before the the if statement, you could add a
the same for the second conditional:
beside the SOQL query inside the for loop, your code looks fine. Let me know what you can get from the logs.