function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Alex AskewAlex Askew 

Create multiple opportunities based on variables from custom object record

Hi,

I have a custom object called 'Product Schedule'. This has the fields; 'Amount', 'Number of Payments', 'Frequency'.  

When a new 'Product Schedule' record is created I would also like it to create multiple opportunities based on the number of payments and frequency. For example if number of payments is 2, amount is £200 and frequency is yearly, it would then want it to automatically create two opportunities worth £100 each and 12 months apart. 

Would this be possible within Visual Workflow and how would you approach it? I've done little bits of apex and process builder before but I'm still getting the hang of visual workflow. 

Thanks,

Alex. 
 

Balayesu ChilakalapudiBalayesu Chilakalapudi
Call an invocable method from your processbuilder or visualworkflow like this,
 
@InvocableMethod
public static void createOpportunity(){
if(no_of_payments==2 && amount==200 && today() < lastpaydate+365 && lastpaydate>today+30){
  List<Opportunity> opplist=new List<Opportunity>();
  Opportunity opp1=new Opportunity();
  opp1.worth=100;
  opplist.add(opp1);
  Opportunity opp2=new Opportunity();
  opp2.worth=100;
  opplist.add(opp2);
  insert opplist;
 duration++;
}
}

Let us know if it helps.