-
Need help with syntex
@isTest
private class RemindOppyOwnersTest {
// Dummy CRON expression: midnight on March 15.
// Because this is a test, job executes
// immediately after Test.stopTest().
public static String CRON_EXP = '0 0 0 15 3 ? 2022';
static testmethod void testScheduledJob() {
// Create some out of date Opportunity records
List<Opportunity> opptys = new List<Opportunity>();
Date closeDate = Date.today().addDays(-7);
for (Integer i=0; i<10; i++) {
Opportunity o = new Opportunity(
Name = 'Opportunity ' + i,
CloseDate = closeDate,
StageName = 'Prospecting'
);
opptys.add(o);
}
insert opptys;
// Get the IDs of the opportunities we just inserted
Map<Id, Opportunity> opptyMap = new Map<Id, Opportunity>(opptys);
List<Id> opptyIds = new List<Id>(opptyMap.keySet());
Test.startTest();
// Schedule the test job
String jobId = System.schedule('ScheduledApexTest',
CRON_EXP,
new RemindOpptyOwners());
// Verify the scheduled job has not run yet.
List<Task> lt = [SELECT Id
FROM Task
WHERE WhatId IN :opptyIds];
System.assertEquals(0, lt.size(), 'Tasks exist before job has run');
// Stopping the test will run the job synchronously
Test.stopTest();
// Now that the scheduled job has executed,
// check that our tasks were created
lt = [SELECT Id
FROM Task
WHERE WhatId IN :opptyIds];
System.assertEquals(opptyIds.size(),
lt.size(),
'Tasks were not created');
}
}
Hi all, need help with the highlighted syntex I am new to salesforce, keyset() return the keys in set so why and how List is used here
Map<Id, Opportunity> opptyMap = new Map<Id, Opportunity>(opptys);
List<Id> opptyIds = new List<Id>(opptyMap.keySet());
Log In to reply.
Popular Salesforce Blogs
How ScoreNotch Helps Salesforce Community Managers Strengthen Their Customer Ties
The success factor for any online community is engagement. If the engagement rate of your community is high, your users will have a deeper connection…
Flows in Salesforce - Brief Guide
Well, now the automation procedures in Salesforce can be taken to another level using Salesforce Flows. Flow is doing an extraordinary job that enables you…
The Simple Formula for Success in Improving Your Business With Marketing Automation | Salesforce
In today's day and age, every business requires a very strong marketing system. Marketing automation is a technology that helps marketers to run their marketing…
Popular Salesforce Videos
Guided Setup with Salesforce Field Service Administration - Webinar Recording
Salesforce Field Service is a complete, end-to-end solution for customer service in the field. Salesforce Field Service brings together customers, employees, and products on a…
Creating Multi Screen Wizard Using Apex and Visualforce Salesforce
Watch this video to learn how to create a Multi-screen wizard using Apex and Visualforce Salesforce. If you have any questions do let us know…
How to setup Visual Studio Code for Salesforce ? | Link VSCode with Non Scratch Org using SFDX CLI
Hello Trailblazers, In this video, we're going to learn how we can setup vscode for Salesforce development. I am going to tell you how you…