Create a List FOR Loop | Quick Start: Apex Coding for Admins

Publié le: 02 juillet 2022
sur la chaîne: Saurabh Infotech Solutions
218
0

#salesforce
#trailhead
#salestraining

Quick Start: Apex Coding for Admins

Add a List FOR loop to iterate through the bankAccts list that you created.

In the Developer Console, open the Execute Anonymous window.
Replace the existing code with this code:
//From the BankAcct class, instantiate an object named chkAcct
BankAcct chkAcct = new BankAcct();
//Set the accttype attribute of the chkAcct object to Checking
chkAcct.accttype = 'Checking';
//Set the acctName attribute of the chkAcct object to D.Castillo-Chk
chkAcct.acctName = 'D.Castillo-Chk ';
//Invoke the makeDeposit method with 150 as the argument
chkAcct.makeDeposit(150);
//From the BankAcct class, instantiate an object named bankAccts
BankAcct savAcct = new BankAcct();
//Set the accttype attribute of the savAcct object to Savings
savAcct.accttype = 'Savings';
//Set the acctName attribute of the savAcct object to D.Castillo-Sav
savAcct.acctName = 'D.Castillo–Sav';
//Invoke the makeDeposit method with 220 as the argument
savAcct.makeDeposit(220);
//From the BankAcct class, instantiate an object named savAcct
ListBankAcctbankAccts = new ListBankAcct();
System.debug('The BankAcct List has ' + bankAccts.size() + ' bank accounts.');
//Add the chkAcct object to the bankAccts list
bankAccts.add(chkAcct);
//Add the savAcct object to the bankAccts list
bankAccts.add(savAcct);
System.debug('The BankAcct List has ' + bankAccts.size() + ' bank accounts.');
System.debug('Here is the list: ' + bankAccts);
//Declare a list FOR loop that uses an iteration variable named tempacct
//to loop through the bankAccts list
for (BankAcct tempacct:bankAccts){
system.debug(tempacct.acctName + ' is a ' + tempacct.accttype +
' account with a balance of $'+ tempacct.getBalance());
}
Verify that Open Log is selected and then click Execute. The execution log opens.
Select Debug Only.
Review the debug messages and then close the log.
In the createContact method, add a List FOR loop to iterate over a Candidate list.

In the CreateContactFromCan class, replace the existing code with this code:
public with sharing class CreateContactFromCan {
//Declare a method that returns void and accepts a Candidate list named candsFromTrigger
public void createContact (ListCandidate__c candsFromTrigger){
//Instantiate a Contact list named conList
ListContact conList = new ListContact);
//Declare a list FOR loop that uses an iteration variable named currentCandidate
//to loop through the candsFromTrigger list
for(Candidate__c currentCandidate:candsFromTrigger){
}
}
}
Save the CreateContactFromCan class.
00:00 Introduction
00:24 Coding
01:05 Verify


Sur cette page du site, vous pouvez voir la vidéo en ligne Create a List FOR Loop | Quick Start: Apex Coding for Admins durée heure minute seconde en bonne qualité , qui a été Téléchargé par l'utilisateur Saurabh Infotech Solutions 02 juillet 2022, Partagez le lien avec vos amis et connaissances, sur youtube cette vidéo a déjà été regardée 218 fois et il a aimé 0 téléspectateurs. Bon visionnage!