I'm very new to apex coding. I was informed that the proper way of creating trigger is to create a trigger then call apex class methods. Is that right?

I tried it on my end with a very simple trigger but I can't make it work. Basically, what I want is that when I create Account, it will automatically create a Contact under the Account with Account is equal to Account id and contact last name is equal to account last name.

Attached is my trigger and class. enter image description here

enter image description here

  • 1
    Please include any code on this exchange as text, not images. Text is significantly more accessible. – Adrian Larson May 25 '17 at 20:52

Your method does not return anything.

change the signature to

public List<Contact> createCont(List<Account> AccRec){

       insert newCont_lst;
       return newCont_lst;


You will also need to change your insertCont to a list of contacts and not a list of accounts as you currently have it

  • 2
    And preferably move the Contact list within the method's scope to avoid unexpected surprises. – sfdcfox May 25 '17 at 21:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.