-
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
Upcoming Market Trends in Salesforce CRM
“SALESFORCE has reached a long distance since late nineties. That was the time, when people use to consider it as a business tool for Salesforce…
Report and Report Type for a Custom Object in Salesforce
It’s an easy task to create a Report for a Standard Object because salesforce provides some standard report types for the standard object, But when…
WordPress Salesforce Integration: The Only Guide You'll Need in 2026
It was a Tuesday afternoon when Sarah, a sales manager at a mid-size B2B software company in Austin, Texas, realized she had a serious problem.…
Popular Salesforce Videos
Salesforce is a fancy database
In this video, We will learn about the Salesforce Database (Data Modelling) in-depth in an interesting and fun way. I have divided this video into…
How to Add 'Add Campaign' Button to the Report Type | Salesforce Tutorial
Do you want to know How to Add 'Add Campaign' Button to the Report Type in Salesforce? In this session, Distinguished Architect Iman Maghroori shows…
Data Migration - Salesforce Admin Tutorial
In this video, Zorial Salesforce Tech gives a quick k overview of how to migrate data using Salesforce. He goes over some key points to…