• Krishnakanth Pamu 1
  • NEWBIE
  • 0 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 4
    Replies
Just i want to generate DML Exception error using below code but it is executing successfully even though i am doing UPDATING USER OBJECT and CREATING AND CREATIGN CUSTOM OBJECT in the SAME APEX CODE..

Below is the code.. Please let me know if i miss to apply anything..


public class TestMixedDmlError {
    
    public static void function1(){
        Indeed_com_AppForm__c i;
        User u = [select id, name, CompanyName from user where name='UserName1'];       
        if(u.CompanyName == null){
            u.CompanyName = u.Name + ' ' + 'Company';
            i = new Indeed_com_AppForm__c();
            i.Name = 'Created from TestMixedDmlError Apex Class';
            insert i;
            update u;
        }
        system.debug(u.CompanyName);
        system.debug(i.name);
          
    }
    
 

}
Hi All,

I have created an email service on opportunity,i got an email address for that email service as 'opportunity_mail@t-14g4wh9lxqs27f99urhsvnojcc6gufofjq3jbl394x9sjsxsdy.28-1ginoeas.ap2.apex.salesforce.com'.when i am adding this email address in Forwarding and POP/IMAP in gmail, i got a message saying ''confirmatio code is sent to opportunity_mail@t-14g4wh9lxqs27f99urhsvnojcc6gufofjq3jbl394x9sjsxsdy.28-1ginoeas.ap2.apex.salesforce.com".Now where can i get that confirmation code?
Hi What are the different type of project deployment tools in salesforce which is best? Thanks Ramesh
  • November 18, 2013
  • Like
  • 0

I'm trying to copy a new user as contact by using a trigger but I'm getting the following 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 Acceleration_User_Copyto_Contact on User (after insert, after update) {
    
   // Map<String,User> newLead = new Map <String, User>();
    
    system.debug('Acceleration_User_Copyto_Contact Trigger....');
 
    for ( User user : System.Trigger.new)
    {
        if  (user.Email.contains('acceleration'))
        {
            system.debug('Acceleration_User_Copyto_Contact Trigger..2.');
            Integer RecordCount = [select count() from Contact c where c.Email = : user.Email];
            
            system.debug('Acceleration_User_Copyto_Contact Trigger..2a .' + RecordCount);
            
            if (RecordCount == 0)
            {
                String AccountId = '';
                for ( Account a : [Select a.Id From Account a where Name = 'Acceleration']) 
                {
                    system.debug('Acceleration_User_Copyto_Contact Trigger..3.');
                     
                    AccountId = a.Id;
                
                    Contact con = New Contact();
                    con.AccountId = AccountId ;
                    con.Email = user.Email;
                    con.Firstname = User.Firstname;
                    con.Lastname = User.Lastname ;
                    con.User__c = User.Id;
                    insert con;
                }          
            }                   
        }
        
     }
    
    
}