You need to sign in to do that
Don't have an account?

mixed dml error generate
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);
}
}
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);
}
}
I found the below article, for example, can you check this once:
>> https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_dml_non_mix_sobjects.htm
I hope this helps and in case if this came in handy in addressing the issue can you please choose this as best answer so that the question is closed and it would in turn help in keeping our community clean, apart from this it would also help others in case if they have a similar issue in the future.
Regards,
Anutej