ffrr.ForecastService
global with sharing class ForecastService
Methods
global static Id generateForecasts(ffrr.ViewService.Tab tab)
global static List<ffrr.ForecastService.Forecast> retrieveByForecastIds(List<Id> forecastIds)
global static List<ffrr.ForecastService.Forecast> retrieveByPrimaryRecordIds(List<Id> primaryRecordIds)
global static List<ffrr.ForecastService.ForecastLine> retrieveDrafts(Id parentRecordId, Integer parentLevel, ffrr.ViewService.Tab tab)
global static List<ffrr.ForecastService.ForecastLine> retrieveLatest(Id parentRecordId, Integer parentLevel, ffrr.ViewService.Tab tab, String category)
global static List<ffrr.ForecastService.ForecastLine> retrieveNew(Id parentRecordId, Integer parentLevel, ffrr.ViewService.Tab tab)
global static List<ffrr.ForecastService.ForecastLine> retrieveSpecific(Id parentRecordId, Integer parentLevel, ffrr.ViewService.Tab tab, Id forecastId)
global static ffrr.ForecastService.Job getJob(Schema.Sobjecttype groupName)
generateForecasts
global static Id generateForecasts(ffrr.ViewService.Tab tab)
Starts the Async Apex Job that generates the Draft forecasts and forecast lines for all the source records that match the filter criteria. The Job ID is returned.
Input Parameters
Return Value
This service returns an ID object.
Sample Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
List<ffrr__RecognitionYear__c> years = [SELECT Id FROM ffrr__RecognitionYear__c];
List<Id> yearIds =
new
List<Id>();
for
(ffrr__RecognitionYear__c year : years)
{
yearIds.add(year.Id);
}
ffrr.ViewService.Tab filters =
new
ffrr.ViewService.Tab();
ffrr.ViewService.TabFilter tabFilter =
new
ffrr.ViewService.TabFilter();
if
(UserInfo.isMultiCurrencyOrganization())
tabFilter.currencyName = UserInfo.getDefaultCurrency();
tabFilter.years = yearIds;
filters.tabFilter = tabFilter;
filters.objectType = Opportunity.getSObjectType();
ID asyncJobID = ffrr.ForecastService.generateForecasts(filters);
retrieveByForecastIds
global static List<ffrr.ForecastService.Forecast> retrieveByForecastIds(List<Id> forecastIds)
Retrieves forecasts for the specified forecast ID's. A list of ffrr.ForecastService.Forecast objects is returned.
Input Parameters
forecastIds
List<Id>
List of forecast id to be retrieved.
Return Value
This service returns a list of ffrr.ForecastService.Forecast objects.
Sample Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
List<ID> forecastIDs =
new
List<ID>();
forecastIDs.add(
'a1ga00000111sg1'
);
forecastIDs.add(
'a1ga00000111sg2'
);
forecastIDs.add(
'a1ga00000111sg3'
);
List<ffrr.ForecastService.Forecast> forecasts = ffrr.ForecastService.retrieveByForecastIDs(forecastIDs);
retrieveByPrimaryRecordIds
global static List<ffrr.ForecastService.Forecast> retrieveByPrimaryRecordIds(List<Id> primaryRecordIds)
Retieves forecasts by top level parent record ID. A list of ffrr.ForecastService.Forecast objects is returned.
Input Parameters
primaryRecordIds
List<Id>
A list of the top level parent ID's.
Return Value
This service returns a list of ffrr.ForecastService.Forecast objects.
Sample Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
List<ID> primaryRecordIDs =
new
List<ID>();
primaryRecordIDs.add(
'a1ga00000111sg1'
);
primaryRecordIDs.add(
'a1ga00000111sg2'
);
primaryRecordIDs.add(
'a1ga00000111sg3'
);
List<ffrr.ForecastService.Forecast> forecasts = ffrr.ForecastService.retrieveByPrimaryRecordIDs(primaryRecordIDs);
retrieveDrafts
global static List<ffrr.ForecastService.ForecastLine> retrieveDrafts(Id parentRecordId, Integer parentLevel, ffrr.ViewService.Tab tab)
Retrieves draft forecast line records when expanding a summary item on the Forecast Revenue page for the specified parent item, applying the supplied filters. The returned data includes both detail and summary items (which may then be used to expand deeper into the available data).
Input Parameters
parentRecordId
Id
The source record ID of the item that is being expanded.
parentLevel
Integer
Recognition settings level of item being expanded. For primary level items use 0 or null.
tab
ffrr.ViewService.Tab
Tab filters to be applied.
Return Value
This service returns a list of ffrr.ForecastService.ForecastLine objects.
Sample Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
Date recognitionDate = Date.newInstance(
2013
,
01
,
05
);
Id yearId = [SELECT Id FROM ffrr__RecognitionYear__c WHERE Name =
'2017'
][
0
].Id;
ffrr.ViewService.Tab filters =
new
ffrr.ViewService.Tab();
ffrr.ViewService.TabFilter tabFilter =
new
ffrr.ViewService.TabFilter();
if
(UserInfo.isMultiCurrencyOrganization())
tabFilter.currencyName = UserInfo.getDefaultCurrency();
tabFilter.recognitionDate = recognitionDate;
tabFilter.years =
new
List<Id>{yearId};
filters.tabFilter = tabFilter;
filters.objectType = Opportunity.getSObjectType();
List<ffrr.ForecastService.ForecastLine> draftForecastLines = ffrr.ForecastService.retrieveDrafts(
null
,
null
, filters);
ID parentRecordID =
null
;
for
(ffrr.ForecastService.ForecastLine draftForecastLine : draftForecastLines )
{
System.debug(
'Forecast line (Root): '
+draftForecastLine);
if
(draftForecastLine.lineType == ffrr.CalculationService.LineType.SUMMARY)
{
parentRecordID = draftForecastLine.record.id;
}
}
if
(parentRecordID !=
null
)
{
draftForecastLines = ffrr.ForecastService.retrieveDrafts(parentRecordID,
1
, filters);
for
(ffrr.ForecastService.ForecastLine draftForecastLine : draftForecastLines)
{
System.debug(
'Forecast line (Child): '
+ draftForecastLine);
}
}
retrieveLatest
global static List<ffrr.ForecastService.ForecastLine> retrieveLatest(Id parentRecordId, Integer parentLevel, ffrr.ViewService.Tab tab, String category)
Retrieves the latest version of forecast lines when expanding a summary item on the Forecast Revenue page for the specified parent item and forecast category, applying the supplied filters. The returned data includes both detail and summary items (which may then be used to expand deeper into the available data).
Input Parameters
parentRecordId
Id
The source record id of the item that is being expanded.
parentLevel
Integer
Recognition settings level of item being expanded. For primary level items use 0 or null.
tab
ffrr.ViewService.Tab
Tab filters to be applied.
category
String
The forecast category to retrieve the latest version of forecast lines for.
Return Value
This service returns a list of ffrr.ForecastService.ForecastLine objects.
Sample Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
Date recognitionDate = Date.newInstance(
2013
,
01
,
05
);
Id yearId = [SELECT Id FROM ffrr__RecognitionYear__c WHERE Name =
'2017'
][
0
].Id;
ffrr.ViewService.Tab filters =
new
ffrr.ViewService.Tab();
ffrr.ViewService.TabFilter tabFilter =
new
ffrr.ViewService.TabFilter();
if
(UserInfo.isMultiCurrencyOrganization())
tabFilter.currencyName = UserInfo.getDefaultCurrency();
tabFilter.recognitionDate = recognitionDate;
tabFilter.years =
new
List<Id>{yearId};
filters.tabFilter = tabFilter;
filters.objectType = Opportunity.getSObjectType();
List<ffrr.ForecastService.ForecastLine> latestForecastLines = ffrr.ForecastService.retrieveLatest(
null
,
null
, filters,
'Best'
);
ID parentRecordID =
null
;
for
(ffrr.ForecastService.ForecastLine latestForecastLine : latestForecastLines )
{
System.debug(
'Forecast line (Root): '
+latestForecastLine);
if
(latestForecastLine.lineType == ffrr.CalculationService.LineType.SUMMARY)
{
parentRecordID = latestForecastLine.record.id;
}
}
if
(parentRecordID !=
null
)
{
latestForecastLines = ffrr.ForecastService.retrieveLatest(parentRecordID,
1
, filters,
'Best'
);
for
(ffrr.ForecastService.ForecastLine latestForecastLine : latestForecastLines)
{
System.debug(
'Forecast line (Child): '
+ latestForecastLine);
}
}
retrieveNew
global static List<ffrr.ForecastService.ForecastLine> retrieveNew(Id parentRecordId, Integer parentLevel, ffrr.ViewService.Tab tab)
Creates zero value forecast lines from the source records with forecast templates attached, that match the filter criteria. The method retrieves those forecast line items when expanding a summary item on the Forecast Revenue page for the specified parent item, applying the supplied filters. The returned data includes both detail and summary items (which may then be used to expand deeper into the available data).
Input Parameters
parentRecordId
Id
The source record id of the item that is being expanded.
parentLevel
Integer
Recognition settings level of item being expanded. For primary level items use 0 or null.
tab
ffrr.ViewService.Tab
Tab filters to be applied.
Return Value
This service returns a list of ffrr.ForecastService.ForecastLine objects.
Sample Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
Date recognitionDate = Date.newInstance(
2013
,
01
,
05
);
Id yearId = [SELECT Id FROM ffrr__RecognitionYear__c WHERE Name =
'2017'
][
0
].Id;
ffrr.ViewService.Tab filters =
new
ffrr.ViewService.Tab();
ffrr.ViewService.TabFilter tabFilter =
new
ffrr.ViewService.TabFilter();
if
(UserInfo.isMultiCurrencyOrganization())
tabFilter.currencyName = UserInfo.getDefaultCurrency();
tabFilter.recognitionDate = recognitionDate;
tabFilter.years =
new
List<Id>{yearId};
filters.tabFilter = tabFilter;
filters.objectType = Opportunity.getSObjectType();
List<ffrr.ForecastService.ForecastLine> newForecastLines = ffrr.ForecastService.retrieveNew(
null
,
null
, filters);
ID parentRecordID =
null
;
for
(ffrr.ForecastService.ForecastLine newForecastLine : newForecastLines )
{
System.debug(
'Forecast line (Root): '
+newForecastLine);
if
(newForecastLine.lineType == ffrr.CalculationService.LineType.SUMMARY)
{
parentRecordID = newForecastLine.record.id;
}
}
if
(parentRecordID !=
null
)
{
newForecastLines = ffrr.ForecastService.retrieveNew(parentRecordID,
1
, filters);
for
(ffrr.ForecastService.ForecastLine newForecastLine : newForecastLines)
{
System.debug(
'Forecast line (Child): '
+ newForecastLine);
}
}
retrieveSpecific
global static List<ffrr.ForecastService.ForecastLine> retrieveSpecific(Id parentRecordId, Integer parentLevel, ffrr.ViewService.Tab tab, Id forecastId)
Retrieves saved forecast line records for a specific forecast record when expanding a summary item on the Forecast Revenue page for the specified parent item, applying the supplied filters. The returned data includes both detail and summary items (which may then be used to expand deeper into the available data).
Input Parameters
parentRecordId
Id
The source record id of the item that is being expanded.
parentLevel
Integer
Recognition settings level of item being expanded. For primary level items use 0 or null.
tab
ffrr.ViewService.Tab
Tab filters to be applied.
forecastId
Id
The ID of the forecast record which lines will be retrieved.
Return Value
This service returns a list of ffrr.ForecastService.ForecastLine objects.
Sample Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
Date recognitionDate = Date.newInstance(
2013
,
01
,
05
);
Id yearId = [SELECT Id FROM ffrr__RecognitionYear__c WHERE Name =
'2017'
][
0
].Id;
ffrr.ViewService.Tab filters =
new
ffrr.ViewService.Tab();
ffrr.ViewService.TabFilter tabFilter =
new
ffrr.ViewService.TabFilter();
if
(UserInfo.isMultiCurrencyOrganization())
tabFilter.currencyName = UserInfo.getDefaultCurrency();
tabFilter.recognitionDate = recognitionDate;
tabFilter.years =
new
List<Id>{yearId};
filters.tabFilter = tabFilter;
filters.objectType = Opportunity.getSObjectType();
ID forecastRecordID =
'a0sa00000011op1'
;
List<ffrr.ForecastService.ForecastLine> specificForecastLines = ffrr.ForecastService.retrieveSpecific(
null
,
null
, filters, forecastRecordID);
ID parentRecordID =
null
;
for
(ffrr.ForecastService.ForecastLine specificForecastLine : specificForecastLines )
{
System.debug(
'Forecast line (Root): '
+specificForecastLine);
if
(specificForecastLine.lineType == ffrr.CalculationService.LineType.SUMMARY)
{
parentRecordID = specificForecastLine.record.id;
}
}
if
(parentRecordID !=
null
)
{
specificForecastLines = ffrr.ForecastService.retrieveSpecific(parentRecordID,
1
, filters, forecastRecordID);
for
(ffrr.ForecastService.ForecastLine specificForecastLine : specificForecastLines)
{
System.debug(
'Forecast line (Child): '
+ specificForecastLine);
}
}
getJob
global static ffrr.ForecastService.Job getJob(Schema.Sobjecttype groupName)
Retrieves the last Generate Forecasting Batch Apex job for the specified group. The returned job will include details such as the status of the job and the number of records processed.
Input Parameters
groupName
Schema.Sobjecttype
Name of the group (Primary Object)
Return Value
The latest job for the specified group or null if no job exists
Sample Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
ffrr.ForecastService.Job jobDetails = ffrr.ForecastService.getJob(Opportunity.SObjectType);
System.debug(
'jobDetails.errorMessage:'
+ jobDetails.ErrorMessage);
System.debug(
'jobDetails.groupName:'
+ jobDetails.GroupName);
System.debug(
'jobDetails.lastDataCreation:'
+ jobDetails.LastCreatedTime);
System.debug(
'jobDetails.progressPercent:'
+ jobDetails.ProgressPercent);
System.debug(
'jobDetails.status:'
+ jobDetails.Status);
ffrr.ForecastService.Job
global with sharing class Job
A Job object represents the state of a Generate Forecasts Batch Apex Job.
Properties
ErrorMessage
String
Any error messages that are generated by the batch job.
GroupName
Schema.SObjectType
Name of the group.
LastCreatedTime
DateTime
Date and time a Create job was last run.
ProgressPercent
Decimal
An indication of the progress of the job as a percentage.
Status
String
The status of the batch job.
ffrr.ForecastService.Forecast
global with sharing class Forecast extends ViewService.Reference
Contains the required details of a forecast record. See other constructors of this class in the Apex Classes under ffrr.ForecastService within Salesforce. See the Salesforce help for more information.
Sample Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
ffrr.ViewService.Reference sampleForecast =
new
ffrr.ViewService.Reference();
sampleForecast.Id =
'a1ga00000111sg6'
;
sampleForecast.Name =
'My Forecast'
;
ffrr.ViewService.Reference sampleRecord =
new
ffrr.ViewService.Reference();
sampleRecord.Id =
'a0ba00000512cc6'
;
sampleRecord.Name =
'My Record'
;
ffrr.ViewService.Reference sampleYear =
new
ffrr.ViewService.Reference();
sampleYear.Id =
'a0sa00000011op1'
;
sampleYear.Name =
'My Project'
;
ffrr.ForecastService.Forecast fSample =
new
ffrr.ForecastService.Forecast();
fSample.Id = sampleForecast.Id;
fSample.name = sampleForecast.Name;
fSample.record = sampleRecord;
fSample.year = sampleYear;
fSample.version =
1
;
fSample.locked =
false
;
fSample.description =
'My Description'
;
fSample.category =
'Best'
;
fSample.totalForecast =
1000000.00
;
Properties
category
String
The forecast category.
categoryLabel
String
The label of the forecast category.
description
String
The forecast description.
locked
Boolean
True = The forecast is locked. False = The forecast is unlocked.
record
ffrr.ViewService.Reference
The reference to the source record.
totalForecast
Decimal
The total forecast amount.
version
Integer
The forecast's version.
year
ffrr.ViewService.Reference
The reference to the forecast's year.
Methods
Forecast
global Forecast(ffrr.ViewService.Reference forecast, ffrr.ViewService.Reference record, ffrr.ViewService.Reference year, Boolean locked, String description, String category, Integer version, Decimal totalForecast)
ffrr.ForecastService.ForecastLine
global with sharing class ForecastLine implements Comparable
Contains the required details for the forecast line. See other constructors of this class in the Apex Classes under ffrr.ForecastService within Salesforce. See the Salesforce help for more information.
Sample Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
ffrr.ForecastService.Forecast sampleForecast =
new
ffrr.ForecastService.Forecast();
sampleForecast.Id =
'a0ba00000512cc6'
;
sampleForecast.Name =
'My Forecast'
;
ffrr.ViewService.Reference sampleRecord =
new
ffrr.ViewService.Reference();
sampleRecord.Id =
'a0sa00000011op1'
;
sampleRecord.Name =
'My Record'
;
ffrr.ViewService.Reference sampleAccount =
new
ffrr.ViewService.Reference();
sampleAccount.Id =
'a0sa00000011ac1'
;
sampleAccount.Name =
'My Account'
;
ffrr.CalculationService.Template sampleTemplate =
new
ffrr.CalculationService.Template();
sampleTemplate.Id =
'a0va00000059tb8'
;
sampleTemplate.Name =
'My Template'
;
ffrr.ForecastService.PeriodLine samplePeriodLine =
new
ffrr.ForecastService.PeriodLine();
samplePeriodLine.Id =
'a0va00000059pl5'
;
samplePeriodLine.Name =
'My Period Line'
;
ffrr.ViewService.Reference projectReference =
new
ffrr.ViewService.Reference();
projectReference.Id =
'a0sa00000011op1'
;
projectReference.Name =
'My Project'
;
ffrr.ViewService.Reference milestoneReference =
new
ffrr.ViewService.Reference();
milestoneReference.Id =
'a0ga00000026abx'
;
milestoneReference.Name =
'My Milestone'
;
ffrr.ViewService.Reference timecardReference =
new
ffrr.ViewService.Reference();
timecardReference.Id =
'a0va00000059tb8'
;
timecardReference.Name =
'My TimeCard'
;
ffrr.ForecastService.ForecastLine flSample =
new
ffrr.ForecastService.ForecastLine(
new
List<ffrr.ForecastService.Forecast>{sampleForecast},
sampleRecord,
sampleRecord.Id,
sampleTemplate,
sampleAccount,
1000000.00
,
2000000.00
,
ffrr.CalculationService.LineType.DETAIL,
new
List<ffrr.ViewService.Reference>{projectReference, milestoneReference, timecardReference},
new
List<ffrr.ForecastService.PeriodLine>{samplePeriodLine}
);
Properties
Methods
global ForecastLine(List<ffrr.ForecastService.Forecast> forecasts, ffrr.ViewService.Reference record, ffrr.CalculationService.Template template, ffrr.ViewService.Reference account, Decimal totalRevenue, Decimal totalForecast, ffrr.CalculationService.LineType lineType, List<ffrr.ViewService.Reference> parentPath, List<ffrr.ForecastService.PeriodLine> periodLines)
global ForecastLine(List<ffrr.ForecastService.Forecast> forecasts, ffrr.ViewService.Reference record, Id linkRecordId, ffrr.CalculationService.Template template, ffrr.ViewService.Reference account, Decimal totalRevenue, Decimal totalForecast, ffrr.CalculationService.LineType lineType, List<ffrr.ViewService.Reference> parentPath, List<ffrr.ForecastService.PeriodLine> periodLines)
ForecastLine
global ForecastLine(List<ffrr.ForecastService.Forecast> forecasts, ffrr.ViewService.Reference record, ffrr.CalculationService.Template template, ffrr.ViewService.Reference account, Decimal totalRevenue, Decimal totalForecast, ffrr.CalculationService.LineType lineType, List<ffrr.ViewService.Reference> parentPath, List<ffrr.ForecastService.PeriodLine> periodLines)
ForecastLine
global ForecastLine(List<ffrr.ForecastService.Forecast> forecasts, ffrr.ViewService.Reference record, Id linkRecordId, ffrr.CalculationService.Template template, ffrr.ViewService.Reference account, Decimal totalRevenue, Decimal totalForecast, ffrr.CalculationService.LineType lineType, List<ffrr.ViewService.Reference> parentPath, List<ffrr.ForecastService.PeriodLine> periodLines)
ffrr.ForecastService.PeriodLine
global with sharing class PeriodLine extends ViewService.Reference
Contains period information for the associated forecast line record.
Sample Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
ffrr.ViewService.Reference sampleYear =
new
ffrr.ViewService.Reference();
sampleYear.Id =
'a1ga00000111sg6'
;
sampleYear.Name =
'2014'
;
ffrr.ForecastService.PeriodLine plSample =
new
ffrr.ForecastService.PeriodLine();
plSample.Id =
'a1ga00000111pl1'
;
plSample.Name =
'0001/2014'
;
plSample.percentage =
10.00
;
plSample.value =
1000000.00
;
plSample.year = sampleYear;
Properties
forecast
Id
The forecast record id associated with the period line.
forecastLine
Id
The forecast line record id associated with the period line.
percentage
Decimal
The percentage value for this period.
value
Decimal
The forecast amount for this period.
year
ffrr.ViewService.Reference
The ID and name of the year that this period belongs to.
Methods
PeriodLine
global PeriodLine(Id id, String name, Id forecast, Id forecastLine, Decimal percentage, Decimal value, ffrr.ViewService.Reference year)