Skip to content

Commit

Permalink
toUpperCase
Browse files Browse the repository at this point in the history
  • Loading branch information
walters954 committed May 6, 2024
1 parent 08981cc commit e8a65b0
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
- Challenge Id: https://www.campapex.org/lesson/1337
- https://www.campapex.org/lesson/stringdeepdive/toupper

*/

/* Example Submission:
String jobTitle = 'software engineer';
String formattedJobTitle = jobTitle.toUpperCase();
return formattedJobTitle;
*/

public class TestException extends Exception{}

public class Solution {
String execute(){
submission
return formattedJobTitle;
}
}

Solution sol = new Solution();

String result = sol.execute();

if(result == null || result != result.toUpperCase){
throw new TestException('Expecting a String variable named \'formattedJobTitle\' and the values should be in uppercase using the toUpperCase() method.');
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
### Lesson on the `toUpperCase()` Method in Apex

**Introduction to `toUpperCase()`**

In Apex programming, text manipulation is a common task, especially when preparing data for comparison or display. One such text manipulation method is `toUpperCase()`, which is used to convert all the letters in a string to uppercase. This can be particularly useful in situations where case uniformity is necessary, such as when processing user input or generating data to be displayed uniformly across an application.

**How `toUpperCase()` Works**

The `toUpperCase()` method is called on a string instance and returns a new string with all the characters converted to their uppercase form. This method does not change the original string but returns a new one with the modifications, as strings in Apex are immutable.

**Example:**
```apex
String message = "Hello, world!";
String shout = message.toUpperCase();
System.debug(shout); // Outputs: "HELLO, WORLD!"
```

In this example, `toUpperCase()` converts every lowercase letter in `message` to its uppercase counterpart, and the result is stored in `shout`.

**Practical Use Case**

Consider a scenario in Salesforce where you need to ensure that all email addresses stored in the database are in a standard format. Since email addresses are case-insensitive, converting them to uppercase before storing or comparing them can help maintain consistency.

```apex
String email = "[email protected]";
String formattedEmail = email.toUpperCase();
System.debug(formattedEmail); // Outputs: "[email protected]"
```

### Challenge: Using `toUpperCase()`

Imagine you are developing a part of a Salesforce application that handles user input for a job application form. The application responses are stored in a custom object, and one of the fields captures the job title of the applicant. To maintain consistency in the database, all job titles need to be stored in uppercase.

**Your task:**
Write a piece of Apex code that accepts a string input representing the job title and converts it to uppercase. Declare a variable `jobTitle` and initialize it with the value of a tech role you would like to have. Example: "software engineer", "Salesforce Developer", "Consultant". Convert `jobTitle` to uppercase and store the result in a new variable `formattedJobTitle`. Finally, return `formattedJobTitle`.

0 comments on commit e8a65b0

Please sign in to comment.