You need to sign in to do that
Don't have an account?
Dolgoldy
Another Script tried
HI All,
Here is another script tried to insert 3 related record for opprtunity for 3 month (Jan,feb,March). But not working can anyone help please.
Script
Map <Id, Opportunity> oppItems = new Map <Id, Opportunity>();
list<ARRCalcualateOpportunity__c> Arropplist= new list<ARRCalcualateOpportunity__c>();
list<Opportunity> opplist= new list<Opportunity>();
for(opportunity opp:opplist){
if (opp.StageName == 'Closed Won'&& opp.closeDate.month() >=1 && opp.closeDate.month() <=3 )
{
oppItems.put(opp.Id, opp);
}
}
List<OpportunityLineItem> oliList = [select Id, Name, Product2Id, Product2.Family from
OpportunityLineItem where OpportunityId IN:oppItems.keyset()];
for(OpportunityLineItem oli :oliList)
{
if(oli.product2.family == 'software Recurring__c')
//Date dt = oppobj.closedate;
for(Integer i =1;i<=12;i++)
{
ARRCalcualateOpportunity__c arrOpp = new ARRCalcualateOpportunity__c();
arropp.name = oppItems.get(oli.OpportunityId).Name;
arropp.ownerId = oppItems.get(oli.OpportunityId).OwnerId;
arropp.OpportunityArr__c=oppItems.get(oli.OpportunityId).Id;
System.debug('arropp list'+arropp);
Arropplist.add(arropp);
System.debug('arropp list'+arropplist);
}
}
if(Arropplist.size() >0){
insert Arropplist;
}
Here is another script tried to insert 3 related record for opprtunity for 3 month (Jan,feb,March). But not working can anyone help please.
Script
Map <Id, Opportunity> oppItems = new Map <Id, Opportunity>();
list<ARRCalcualateOpportunity__c> Arropplist= new list<ARRCalcualateOpportunity__c>();
list<Opportunity> opplist= new list<Opportunity>();
for(opportunity opp:opplist){
if (opp.StageName == 'Closed Won'&& opp.closeDate.month() >=1 && opp.closeDate.month() <=3 )
{
oppItems.put(opp.Id, opp);
}
}
List<OpportunityLineItem> oliList = [select Id, Name, Product2Id, Product2.Family from
OpportunityLineItem where OpportunityId IN:oppItems.keyset()];
for(OpportunityLineItem oli :oliList)
{
if(oli.product2.family == 'software Recurring__c')
//Date dt = oppobj.closedate;
for(Integer i =1;i<=12;i++)
{
ARRCalcualateOpportunity__c arrOpp = new ARRCalcualateOpportunity__c();
arropp.name = oppItems.get(oli.OpportunityId).Name;
arropp.ownerId = oppItems.get(oli.OpportunityId).OwnerId;
arropp.OpportunityArr__c=oppItems.get(oli.OpportunityId).Id;
System.debug('arropp list'+arropp);
Arropplist.add(arropp);
System.debug('arropp list'+arropplist);
}
}
if(Arropplist.size() >0){
insert Arropplist;
}
Even though there are many areas of improvement on this piece of code, functionally it should work. A couple of thoughts below -
- It only works on Closed Won opportunities
- For eligible opportunities, it only works for OpportunityLineItems with product2.family == 'software Recurring__c'
- Let's add opening brace({) after
and wrap whatever code you want inside this if clause before you add a closing brace (}). That will save you from different issues down the road- I am not sure about the significance of for loop with static count 12. Do we want to make 12 ARRCalcualateOpportunity__c records for each eligible OpportunityLineItem ( because of 12 months)?
- What is not working in this code? Are you getting any errors running this? Is it not creating the records and not giving any errors? How are you invoking this code ( using apex trigger/batch etc ?). Can you please provide more information regarding this?
ThanksAll Answers
Even though there are many areas of improvement on this piece of code, functionally it should work. A couple of thoughts below -
- It only works on Closed Won opportunities
- For eligible opportunities, it only works for OpportunityLineItems with product2.family == 'software Recurring__c'
- Let's add opening brace({) after
and wrap whatever code you want inside this if clause before you add a closing brace (}). That will save you from different issues down the road- I am not sure about the significance of for loop with static count 12. Do we want to make 12 ARRCalcualateOpportunity__c records for each eligible OpportunityLineItem ( because of 12 months)?
- What is not working in this code? Are you getting any errors running this? Is it not creating the records and not giving any errors? How are you invoking this code ( using apex trigger/batch etc ?). Can you please provide more information regarding this?
Thanks