• Zafer Kahraman
  • NEWBIE
  • 0 Points
  • Member since 2022

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 2
    Replies

Hi Everyone,

I am trying to create a new contact record when the new user is created.

This trigger code gives this error.


trigger NewContactOnUser on User (after insert) {
    List<Contact> contacts = new List<Contact>();
    for (User u: trigger.new){
        Contact c = new Contact();
        c.FirstName = u.FirstName;
        c.LastName = u.LastName;
        contacts.add(c);       
    }
    insert contacts;

 

Error is this..

Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger NewContactOnUser caused an unexpected exception, contact your administrator: NewContactOnUser: execution of AfterInsert caused by: System.DmlException: Insert failed. First exception on row 0; first error: MIXED_DML_OPERATION, DML operation on setup object is not permitted after you have updated a non-setup object (or vice versa): Contact, original object: User: []: Trigger.NewContactOnUser: line 9, column 1
    

 

Hi Everyone,

I am trying to create a new contact record when the new user is created.

This trigger code gives this error.


trigger NewContactOnUser on User (after insert) {
    List<Contact> contacts = new List<Contact>();
    for (User u: trigger.new){
        Contact c = new Contact();
        c.FirstName = u.FirstName;
        c.LastName = u.LastName;
        contacts.add(c);       
    }
    insert contacts;

 

Error is this..

Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger NewContactOnUser caused an unexpected exception, contact your administrator: NewContactOnUser: execution of AfterInsert caused by: System.DmlException: Insert failed. First exception on row 0; first error: MIXED_DML_OPERATION, DML operation on setup object is not permitted after you have updated a non-setup object (or vice versa): Contact, original object: User: []: Trigger.NewContactOnUser: line 9, column 1
    

 

hi floks

i have one requirment 

if check box is checked and associate piclkist field is enble .and it's unchecked picklist field was disable .

how to do this requirment ?