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
David GlickDavid Glick 

activate trigger

I am new to Salesforce.com.  I am following the example in the Force.com IDE manual and created the trigger and class, however, when I add an Account, the Description field is not populated with "Hello World".  So it seems my trigger and class are not getting activated.

Also, when I went to save in Eclipse, I got a message that it was not in sync with the organization, but I continued anyway.  My class and trigger are saved on the site though so it seems things are ok.
Best Answer chosen by David Glick
David GlickDavid Glick
Ajay,

I just figured it out.  I have to save the account first.  I was thrown by the “before insert” thinking it would appear in the dialog before I do the save (insert).
 
I am truly a newbie.

Thank you for your guidance.

All Answers

Ajay Ghuge 6Ajay Ghuge 6
David,

Post the trigger/class code so that all can check for the issue. There are multiple reasons for it : 
1. Trigger may be not active
2. Trigger events are not correct
3. Code is not saved on salesforce

Regards,
Ajay
David GlickDavid Glick
Ajay, This is the class code: public class MyHelloWorld { // This method updates the Description field for a list // of accounts to read "Hello World". public static void addHelloWorld(Account[] accs) { for (Account a:accs) { if (a.Description != 'Hello World') a.Description = 'Hello World'; } } } This is the trigger code: trigger helloWorldAccountTrigger on Account (before insert) { MyHelloWorld.addHelloWorld(Trigger.new); } Thanks, David.
David GlickDavid Glick
Sorry that the code is formatted as one continuous line.  I do have the code on salesforce.com and I have verified that the trigger and class are in "active" status.
Ajay Ghuge 6Ajay Ghuge 6
David,

I tried same code in my developer org and its working as expected.

User-added image

Do check if your org is having any other triggers or process builder or workflow causing the problem.

Regards,
Ajay
David GlickDavid Glick
Ajay,

When I try to test it, I go to the "Service" app, Accounts tab and click the "New" button.  I then scroll down to the "Description" field and it is not populated with the text.  Is that what you did?  If not, please tell me what you did so I can do the same.  As for other triggers, etc., I just created this developer org yesterday morning so there should be nothing else on it other than this trigger and class.

Thanks,

David.
David GlickDavid Glick
Ajay,

I found that if I add an account through the Developer Console, the trigger is fired and works fine.  Is it not expected to work when adding an Account interactively?

Thanks,

David.
David GlickDavid Glick
Ajay,

I just figured it out.  I have to save the account first.  I was thrown by the “before insert” thinking it would appear in the dialog before I do the save (insert).
 
I am truly a newbie.

Thank you for your guidance.
This was selected as the best answer
Ajay Ghuge 6Ajay Ghuge 6
David,

Yes, you need to click save to see the result.

I will suggest mark any of yours or my answer as best answer and mark it resolved.

Regards,
Ajay