-
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
10 Warning Signs Your Salesforce Implementation Is Heading for Disaster
Salesforce is a powerful Customer Relationship Management (CRM) tool that helps businesses streamline operations, enhance customer interactions, and drive business growth. However, the journey from…
Increases in Governor Limits in SFDC Winter 17 Release.
With Winter 17 Release many Governor Limits have Increased.“You didn't see that coming?” 1. Salesforce Daily Org Limits for Sending Emails with the API Have…
Why MuleSoft is the Perfect Integration Platform for Your Business?
Organizations integrate their business applications primarily to expand their business operations and reach their customers quickly. But integration doesn't just involve the systems and services;…
Popular Salesforce Videos
Difference between B2B, B2C and B2B2C Salesforce Commerce Cloud?
There is a lot of buzz about the Salesforce commerce cloud and its effective offerings. Let’s dive deep into the world of Salesforce and the…
Data Import: Clean and Prepare Your Data Using Excel | Salesforce
Cleaning and Preparing Data Using Excel covers several features and functions that will make quick work of getting your data files ready for import. Vlookup,…
Salesforce Developer Tutorial - How and When to Use Apex Managed Sharing
In this episode, we go over what Apex Managed Sharing is in Salesforce when you should actually use apex managed sharing and how to actually…