Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Salesforce by (13.1k points)

I am new to Apex and I am not able to understand this code. What is the meaning of the line System.assertEquals(color1, color2);

String color1 = moreColors.get(0);

String color2 = moreColors[0];

System.assertEquals(color1, color2);

// Iterate over a list to read elements

for(Integer i=0;i<colors.size();i++) {

    // Write value to the debug log

    System.debug(colors[i]);

}

Can anyone help me with this?

1 Answer

0 votes
by (26.7k points)

These are called assert statements, which are usually used for testing to validate that the data what you have is matches your expectations or not. Basically, System.assertEquals tests that if two values are equal or not, if they are equal then the code kept on running else it will throws an exception.

I hope this will help. 

Want to become a Salesforce Expert? join Salesforce certification now!

Related questions

0 votes
1 answer
0 votes
0 answers

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...