Skip to content

Exercise #3 - Batch and Scheduled Jobs#3

Open
orhanea wants to merge 4 commits intomainfrom
Exercise-#3
Open

Exercise #3 - Batch and Scheduled Jobs#3
orhanea wants to merge 4 commits intomainfrom
Exercise-#3

Conversation

@orhanea
Copy link
Copy Markdown
Owner

@orhanea orhanea commented Aug 30, 2021

No description provided.

@orhanea orhanea requested a review from aliozdemirosf August 30, 2021 09:04
Comment on lines +18 to +20
global Iterable<SObject> start(Database.BatchableContext batchable) {
return overviewResult;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should return a query locator here instead of iterable. reason of batch is to chunk great amount of data. Iterable will fail on that scenario

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the code but I did not understand which query I write instead of overviewResult variable

Comment thread ThirdProject/force-app/main/default/classes/OverviewOpportunityAmountsBatch.cls Outdated
Comment on lines +18 to +45
primaryContacts = [SELECT ID, AccountId, Email
FROM Contact
WHERE Is_Primary_Contact__c = true];

// Fill the map object.
for (Contact primary : primaryContacts) {
if (!primaryEmails.containsKey(primary.AccountId)){
primaryEmails.put(primary.AccountId, primary.Email);
}
}

// Searching for who has a primary contact "Used in the WHERE clause".
Set<Id> accountIdSet = primaryEmails.keySet();

// Time.
DateTime nowDate = System.now();
Date startDate = Date.newinstance(nowDate.year(), nowDate.month(), 1);

System.debug('Schedule is starting for: ' + string.valueOfGmt(startDate));

overviewResult = [SELECT AccountId, Account.Name AccountName, StageName, format(sum(Amount))SumAmount
FROM Opportunity
WHERE AccountId in :accountIdSet
AND (CreatedDate >= :startDate or LastModifiedDate >= :startDate)
GROUP BY AccountId, Account.Name, StageName
ORDER BY AccountId];

// Execute.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be handled inside batch apex.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it okey to keep constructor in the batch ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants