Skip to content

Instantly share code, notes, and snippets.

@shivanathd
Created September 11, 2013 09:00
Show Gist options
  • Save shivanathd/6521075 to your computer and use it in GitHub Desktop.
Save shivanathd/6521075 to your computer and use it in GitHub Desktop.
@isTest(SeeAllData= true)
private class CaseCommentHelperTest {
static testMethod void CaseCommentValid() {
//Create a Case Team role
CaseTeamRole CTR = new CaseTeamRole();
CTR.AccessLevel='Edit';
CTR.Name='Test Case Team Role';
CTR.PreferencesVisibleInCSP=true;
// To avoid the Mixed DML operation Error we start a new Context
System.runAs(new User(Id = Userinfo.getUserId())) {
insert CTR;
}
System.assert(CTR!=null);
Case newCase = new Case();
newCase.Status='New';
newCase.Origin='Phone';
newCase.Subject='Test';
newCase.Description='Test Description';
insert newCase;
System.assert(newCase!=null);
List<contact> newContacts = new List<contact>();
integer RecordsToBeCreated = 3;
newContacts=CaseCommentHelperTest.CreateNewContactList(RecordsToBeCreated);
insert newContacts;
System.assert(newContacts.size()==RecordsToBeCreated);
// User u = [select id from User ]
UserLicense UL = [Select u.id From UserLicense u where u.name='Salesforce' Limit 1];
List<profile> profiles= [Select id from profile where UserLicenseID = :UL.id];
// Select The Active Users with this profile
List<User> ActiveUsers = [select id from User where ProfileId in:profiles and IsActive =true Limit 3];
List<CaseTeamMember> CTMs = new List<CaseTeamMember>();
//Add a User to Case Team
for(User u : ActiveUsers)
{
CaseTeamMember CTM = new CaseTeamMember();
CTM.MemberId=u.id;
CTM.ParentId=newCase.id;
CTM.TeamRoleId = CTR.Id;
CTMs.add(CTM);
}
//Add Contacts to Case Team
for(Contact c : newContacts)
{
CaseTeamMember CTM = new CaseTeamMember();
CTM.MemberId=c.id;
CTM.ParentId=newCase.id;
CTM.TeamRoleId = CTR.Id;
CTMs.add(CTM);
}
insert CTMs;
Insert CaseCommentHelperTest.CreateNewCaseCommentList(5,newCase.Id);
}
//======== Utility Methods============
public static List<CaseComment> CreateNewCaseCommentList(integer MaxRecord,Id CaseID)
{
List<CaseComment> newCaseCommentList = new List<CaseComment>();
for(integer i=0;i<MaxRecord;i++)
{
CaseComment cc= new CaseComment();
cc.CommentBody='Hello '+i;
cc.ParentId =CaseID;
cc.IsPublished=true;
newCaseCommentList.add(cc);
}
return newCaseCommentList;
}
public static List<Contact> CreateNewContactList(integer MaxRecord)
{
List<Contact> NewContactList = new List<Contact>();
for(integer i=0;i<MaxRecord;i++)
{
Contact c = new Contact();
c.LastName='NewContact'+i;
c.Email='test'+i+'@tester.com';
NewContactList.add(c);
}
return NewContactList;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment