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
naga kiran 2naga kiran 2 

MIXED_DML_OPERATION, DML operation on setup object is not permitted after you have updated a non-setup object

I have an error  while firing a trigger i need create a user record from custom object below is the code pls resolve it ASAP...

trigger createportaluser on Compliance_Diligence_Association__c (after insert) {

list<user> userList = new list<user>();
    for(Compliance_Diligence_Association__c objcustom : [SELECT GLD_Submit_Case__c ,GLD_Business_Contact__r.Id,GLD_Business_Contact__r.FirstName,GLD_Business_Contact__r.LastName,GLD_Business_Contact__r.Email FROM Compliance_Diligence_Association__c where id in:]){
          if( objcustom.GLD_Submit_Case__c == true){
    User u = new User();
         u.LocaleSidKey = 'en_US';
         u.LanguageLocaleKey = 'en_US';
         u.alias = string.valueof(objcustom.GLD_Business_Contact__r.FirstName.substring(0,1) + objcustom.GLD_Business_Contact__r.LastName.substring(0,1));
         u.profileid = '00e61000000ndg3'; 
         u.CommunityNickname=string.valueof(objcustom.GLD_Business_Contact__r.FirstName.substring(0,1) + objcustom.GLD_Business_Contact__r.LastName.substring(0,1));



You should use @future class to avoid this error , Try this :

naga kiran 2naga kiran 2
Hi nilesh,

I am new to apex coding can you please seggregate above trigger to be future that i will learn...