Salesforce Shots: Test Data Factory in Salesforce

@isTest public class TestDataFactory { public static User createUser() { 
Profile pf = [SELECT Id,Name FROM Profile WHERE Name = 'System Administrator' LIMIT 1];
User usr = new User( Alias = 'usralias', Email = 'theuser@email.com', Emailencodingkey = 'UTF-8', Lastname = 'user_lastname', Languagelocalekey = 'en_US', Localesidkey = 'en_US', Profileid = pf.Id, Timezonesidkey = 'America/Los_Angeles', Username = Math.random() + 'test@testuser.com', CompanyName = 'the company' ); insert usr;
return usr;
}
public static User createCommunityUser(){ String uniqueUserName = 'CommuntiyUser' + DateTime.now().getTime() + '@testorg.com'; // This code runs as the system user
Profile p = [SELECT Id FROM Profile WHERE Name='Intforce Partner Profile'];
User u = new User(Alias = 'comut', Email='commuser@testorg.com', EmailEncodingKey='UTF-8', LastName='Testing', LanguageLocaleKey='en_US', LocaleSidKey='en_US', ProfileId = p.Id, TimeZoneSidKey='America/Los_Angeles', UserName=uniqueUserName); return u;
}
}
@isTest public void createUserTest() { User SystemAdmin = TestDataFactory.createUser(); }
@isTest public void createUserTest() { System.runAs(SystemAdmin){ 
User PartnerUser = TestDataFactory.createCommunityUser();
}
}

--

--

intforce software is software service company and providing complete IT solution with fresh perspective. https://intforcesoftware.com/

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Intforce Software

Intforce Software

intforce software is software service company and providing complete IT solution with fresh perspective. https://intforcesoftware.com/