function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Jeremy GaisieJeremy Gaisie 

Calling a Class Method from a Trigger

Note: This is not a 'challenge' related question. I'm either experiencing a bug or have another issue preventing account creation in the Salesforce UI.

The tutorial link can be found here (https://developer.salesforce.com/trailhead/apex_triggers/apex_triggers_intro):
I'm having difficulty following the Trailhead Tutorial titled: 'Getting Started with Apex Triggers', from section: 'Calling a Class Method from a Trigger'. The step I am following is copied from th etutorial here:
1) Add the following trigger using the Developer Console (follow the steps of the HelloWorldTrigger example but useAddRelatedRecord for the trigger name).
2) To test the trigger, create an account in the Salesforce user interface and name it Apples & Oranges.
User-added image
(this image may be too small to read, the solution is to open it in another tab)

I have copied and pasted the code for all of the relevant classes and triggers in this tutorial and have used the described titles. I am using HaoIDE for my text editor, however I don't believe this is an issue, as copies are saved to the Salesforce Platform.

What 'discount' is being referred to in the error message? I was under the impression that the only required field for an account is the name?
I believe I can continue to create accounts by removing the related trigger but would prefer to find answers to this problem, if possible.

Thanks in advance to any suggestions
Best Answer chosen by Jeremy Gaisie
Jeremy GaisieJeremy Gaisie
Solution: Discount_Percent__c is the required field that is missing - This is created from a previous tutorial and either needs to be disabled or included in the tutorial section as follows (from line 16):

oppList.add(new Opportunity(Name=a.Name + ' Opportunity',
                                       StageName='Prospecting',
                                       CloseDate=System.today().addMonths(1),
                                       AccountId=a.Id,
                                       Discount_Percent__c=0)); //Add 0 or your chosen percentage

All Answers

Jithin Krishnan 2Jithin Krishnan 2
Hi Jeremy,
I just tried the trigger and it worked without any errors. Please make sure that you don't have any validation rules or triggers enabled on Account object. You can check them under 
Setup -> Accounts -> Triggers
Setup -> Accounts -> Validation Rules
Make them inactive and try again. Thanks!
Jeremy GaisieJeremy Gaisie
Solution: Discount_Percent__c is the required field that is missing - This is created from a previous tutorial and either needs to be disabled or included in the tutorial section as follows (from line 16):

oppList.add(new Opportunity(Name=a.Name + ' Opportunity',
                                       StageName='Prospecting',
                                       CloseDate=System.today().addMonths(1),
                                       AccountId=a.Id,
                                       Discount_Percent__c=0)); //Add 0 or your chosen percentage
This was selected as the best answer