1

I have 2 lists, they show the ForecastingQuota of my users for Quarter 1 and Quarter 2. I want to copy all the values of Quarter 1 to Quarter 2 if I choose the quarter on the SelectList (just copy the quota Amount of the user). How can I achieve this?

<apex:outputText>Copy Quarter</apex:outputText>
<apex:selectList value="{!selectedQuarterToCopy}"  size="1">
    <apex:selectOptions value="{!QuarterList}" />
</apex:selectList>
<apex:outputText>To this Quarter</apex:outputText>
<apex:selectList value="{!selectedQuarterCopied}"  size="1">
    <apex:selectOptions value="{!QuarterList}" />
</apex:selectList>

<apex:commandButton value="Copy Quarter to Quarter" action="{!copyQuarterToQuarter}" styleClass="buttonCopyQuota" reRender="null" />

List<ForecastingQuota> queryQuotaListQ1 = [SELECT Id, QuotaAmount, QuotaOwnerId, QuotaOwner.UserRole.Name, StartDate FROM ForecastingQuota WHERE ForecastingTypeId = :forecastTypeList.get(0).Id AND StartDate >=:selectedQuarterQ1 AND StartDate <:selectedQuarterQ2 AND QuotaOwnerId IN : userIdSet ORDER BY QuotaOwnerId ASC];
List<ForecastingQuota> queryQuotaListQ2 = [SELECT Id, QuotaAmount, QuotaOwnerId, QuotaOwner.UserRole.Name, StartDate FROM ForecastingQuota WHERE ForecastingTypeId = :forecastTypeList.get(0).Id AND StartDate >=:selectedQuarterQ2 AND StartDate <:selectedQuarterQ3 AND QuotaOwnerId IN : userIdSet ORDER BY QuotaOwnerId ASC];

example

  • I don't understand your question. Cant' you just make a queryQuotaListQ2.addAll(queryQuotaListQ1)? – Martin Lezer Jan 5 '17 at 15:58
  • I have update my post with a picture. In the first column I get the Quota for Quarter 1 2017, in the next column I have Quota for Q2 2017. And with the picklist and button in yellow, here I want to choose and copy the values of Selected Quarter (Quota Amount for each users) in an other Quarter, like duplicate values for different Quarter. Thx – Jeremy Deseez Jan 5 '17 at 16:14
  • 1
    How about you clone th list and then iterate through the newly copied list and change the values to th new quarter? – Sebastian Kessel Jan 5 '17 at 16:24
0

I second the idea of cloning and looping through. So basically you would do something like

 // get start date of next quarter
startOfQuarter = [Select startDAte From Period Where type = 'Quarter' and StartDate = THIS_FISCAL_QUARTER].startdate; 
startofQuarter = startOfQuarter + 100; 
startOfQuarter = startOfQuarter.toStartOfMonth();

List<ForecastingQuota> queryQuotaListQ1 = [SELECT Id, QuotaAmount, QuotaOwnerId, QuotaOwner.UserRole.Name, StartDate FROM ForecastingQuota WHERE ForecastingTypeId = :forecastTypeList.get(0).Id AND StartDate >=:selectedQuarterQ1 AND StartDate <:selectedQuarterQ2 AND QuotaOwnerId IN : userIdSet ORDER BY QuotaOwnerId ASC];
List<ForecastingQuota> queryQuotaListQ2 = new List<ForecastingQuota> queryQuotaListQ2();
for(ForecastingQuota forecast: queryQuotaListQ1) {
    ForecastingQuota newForecast = forecast.clone(false, false, false, false);
    newForecast.startDate = startOfQuarter;
    queryQuotaListQ2.add(newForecast);

}
insert queryQuotaListQ2

;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.