-
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
Salesforce's Latest Mascot is here: Flo, The Flying Squirrel
Recently, Salesforce introduced a new mascot, a friend of Astro and family, Flo. With the help of automation, this flying squirrel will assist you in…
Power of Search in Salesforce
Power of Search Salesforce Search: We use the built-in search function of the Salesforce platform to search for any record or file. It gives us…
Top 5 Feature Updates in Salesforce Spring ‘20 Release
Hello everyone and welcome to 2020! We hope you all enjoyed the holidays and had a nice new year! With a new year brings a…
Popular Salesforce Videos
How to Learn Salesforce in easy step by step and get certified
From Salesforce instructor, Become a Salesforce Expert. Learn Salesforce step by step and get certified easily.
Top 4 Ways Sales Leaders at Salesforce Use Einstein Analytics
Here's a peek behind the curtain at four of the top ways sales leaders at Salesforce use Einstein Analytics to manage pipeline and coach their…
The Salesforce Team is Talking About What Working for Salesforce is Like
The Salesforce team is talking about what working for Salesforce is like. Watch this video learn about their experience.