+ Start a Discussion
Alex Valavanis 10Alex Valavanis 10 

What am i doing wrong? Get started with Apex triggers

Hello, I'm doing the following exercise but Debug LOg tells me i have a problem.

Traihead says to do the following:

User-added image

I replace my email address and the following comes up:

User-added image
Best Answer chosen by Alex Valavanis 10
sfdcMonkey.comsfdcMonkey.com
Yes trailhead need to update there instructions,
    and the reason is you can't call something that doesn't exist. Since you haven't created an object, the non-static method doesn't exist yet. A static method (by definition) always exists.
 you can learn more about it here : https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_static.htm?search_text=static 

Hope it wil helps you, if it helps you kindly close your query by choosing best answer so it make proper solution for others in future 

All Answers

sfdcMonkey.comsfdcMonkey.com
hi, open your EmailManager apex class , and use static keyword in sendMail method such as :

public static void sendMail(....

after save apex class, save your trigger code,

OR don't change in apex class just update your trigger code with following code :

trigger ExampleTrigger on Contact (after insert, after delete) {
    if (Trigger.isInsert) {
        Integer recordCount = Trigger.New.size();
        // Call a utility method from another class
        EmailManager obj = new EmailManager(); 
         obj.sendMail('Your email address', 'Trailhead Trigger Tutorial', 
                    recordCount + ' contact(s) were inserted.');
    }
    else if (Trigger.isDelete) {
        // Process after delete
    }
}


Thanks, let us know if it helps you 

 
Alex Valavanis 10Alex Valavanis 10
Hello, Thank you i followed your second option and problem was resolved (have no idea about Apex class).

I am totally new to Apex and this is my first tutorial. What went wrong and why doesn't trailhead updated the instruction ?

I actually don't understand of what you did.
sfdcMonkey.comsfdcMonkey.com
Yes trailhead need to update there instructions,
    and the reason is you can't call something that doesn't exist. Since you haven't created an object, the non-static method doesn't exist yet. A static method (by definition) always exists.
 you can learn more about it here : https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_static.htm?search_text=static 

Hope it wil helps you, if it helps you kindly close your query by choosing best answer so it make proper solution for others in future 
This was selected as the best answer