Tag Archives: User

Check Case Owner is a User or Queue

Check Case Owner in Apex Class.

//Check object Id in Apex 
if(string.valueOf(c.OwnerId).startsWith('005')){
    //Owner is User       
}

if(string.valueOf(c.OwnerId).startsWith('00G')){
    //Owner is Queue
}

Check Case Owner in Apex Trigger.

//In Apex Trigger
for (Case objCase : Trigger.new) { 
    If (objCase.OwnerID.getsobjecttype() == User.sobjecttype) {
        /*Code if Owner is User*/
    }
    else{
        /*Code if Owner is Queue*/ 
    }
}

Check Case Owner by SOQL query.

//By Query Owner.Type Field
List<Case> caseList = [SELECT Id, CaseNumber, OwnerId, Owner.Name, Owner.Type FROM Case];

for (Case objCase : caseList){
    If (objCase.Owner.Type == User.sobjecttype) {
        /*Code if Owner is User*/
    }
    else{
        /*Code if Owner is Queue*/ 
    }
}

Check Case Owner in Process Builder.

//Check in Process Builder
BEGINS([Case].OwnerId, "005") //Check Owner is User
BEGINS([Case].OwnerId, "00G") //Check Owner is Queue

Salesforce Create User Using Apex

Sample Code:

//Get Profile Id
Profile objProfile = [SELECT Id FROM Profile WHERE Name = 'Standard User' LIMIT 1];
//Add User Information
User objUser = new User();
objUser.FirstName='Biswajeet';
objUser.LastName = 'Samal';
objUser.Alias = 'Biswa';
objUser.Email = 'itzbiswajeet@gmail.com';
objUser.Username = 'itzbiswajeet@gmail.com';
objUser.ProfileId = profileId.id;
objUser.TimeZoneSidKey = 'GMT';
objUser.LanguageLocaleKey = 'en_US';
objUser.EmailEncodingKey = 'UTF-8';
objUser.LocaleSidKey = 'en_US';
//Insert User
Insert objUser;