You need to sign in to do that
Don't have an account?
Steve Connelly 5
I could use a little help with nested "while" loops in a trigger.
Good morning all. I have a trigger that creates new records related to opportunities.
I have everything working but my loop and i am stuck. I am very new to coding and would really appreciate some assistance.
This iwhat I have so far and everything works...except....
Now I have four custom formula fields in the opp that I can use.
But the rest is all very new to me. How do I build these nested loops with an output for each iteration that looks like this "2019-Q1" that I can use in creating my new records.
I am really stuck here so any help at all will be greatly appreciated.
Best regards,
Steve
I have everything working but my loop and i am stuck. I am very new to coding and would really appreciate some assistance.
This iwhat I have so far and everything works...except....
//while loop create record process decimal counter = 0; while (counter < opportunityList.Quarters_Spanned_op__c) { Open_Quarter__c oq = new Open_Quarter__C(); Quarter_Number__c qn = new Quarter_Number__c(); oq.Amount_Per_Quarter_oq__c = opportunityList.Amount_per_Quarter_op__c; oq.Close_Date_oq__c = opportunityList.CloseDate; oq.Name = opportunityList.Quarter_Created_op__c; oq.Opportunity_Name_oq__c = opportunityList.Id; oq.Quarters_Spanned_oq__c = opportunityList.Quarters_Spanned_op__c; createOpenQuarter.add(oq); counter++; }//end while loopWhen I create each new record I need it to populate a field in that record with escalating quarter names. Right now it creates the right nimber of records but they all have the same quarter name in them which the starting quarter of the opp.
Now I have four custom formula fields in the opp that I can use.
- One with the name for the quarter when the opp was created in this format: 2019-Q1 etc
- One with the year the opp was started as a number "2019"
- One with the starting quarter as a number (1-4)
- One with the number of quarters the opp spanse based upon the created and close dates also expressed as a number.
But the rest is all very new to me. How do I build these nested loops with an output for each iteration that looks like this "2019-Q1" that I can use in creating my new records.
I am really stuck here so any help at all will be greatly appreciated.
Best regards,
Steve
Hi Steve,
You can create one formula field, where you can define the structure as YYYY-Q1 (find link below, )
https://success.salesforce.com/answers?id=9063A000000idPQQAY
Use that formula field to assign to that field on opporunity.
Thanks,
Sucharita
All Answers
Hi Steve,
You can create one formula field, where you can define the structure as YYYY-Q1 (find link below, )
https://success.salesforce.com/answers?id=9063A000000idPQQAY
Use that formula field to assign to that field on opporunity.
Thanks,
Sucharita