You need to sign in to do that
Don't have an account?
Gunnam Ram
Test class Problem: case creation from chatter group post
I am working on a class which creates an case if we post something in a chatter group. My code is working as expected nut I cannot cover the code inside two IF blocks in my test class. Can any one please suggest.
My class:
Id parentID = Feeditem.ParentId;
String groupName;
string smartBarLabel = Label.SmartBar_Custom_Label;
string IPToolLabel = Label.IP_Tool_Support_custom_label;
Map<id,CollaborationGroup> CollaborationGroupName = new Map<id,CollaborationGroup>([select id, Name from CollaborationGroup where CollaborationType='Public' and ID in :FeedId]);
Case css = new Case();
if(CollaborationGroupName.size() > 0) {
groupName = CollaborationGroupName.get(parentID).Name;
}
if(groupname!=null && groupName.equalsIgnoreCase(smartBarLabel)) {
css.RecordTypeId = ind.id;
if(SmartBarID!=null)
css.OwnerId=smartBarID;
}
else if(groupname!=null && groupname.equalsIgnoreCase(IPToolLabel)) {
css.Recordtypeid=IPind.id;
if(IPToolID!=null)
css.OwnerId=IPToolID;
}
css.Chatter_Name__c=Feedpost.CreatedById;
css.Description=FeedBody;
css.Subject=Feedpost.Title;
//css.Reason='Function';
//css.OwnerId=Label.CaseQueueOwner;
css.Type='Chatter';
css.FeedItemId__c=feedpost.id;
if(Feedpost.Title==null) css.Subject=FeedBody;
system.debug('the feedpostparent********'+css.FeedItemId__c);
csslist.add(css);
Test Class :
CollaborationGroup cg2 = new CollaborationGroup(Name='xxxx', CollaborationType='Public');
cg2.OwnerId=u1.Id;
insert cg2;
FeedItem fitem2 = new FeedItem();
fitem2.Body = 'yyyyy';
fitem2.CreatedById = u1.Id;
fitem2.ParentId = cg2.Id;
insert fitem2;
String groupnm = cg2.Name;
Case aCase = new Case();
system.assert(groupnm == 'xxxx');
system.assert(groupnm!=NULL);
aCase.OwnerId = testGroup.Id;
aCase.Recordtypeid=ind.id;
aCase.Description='FeedBody';
aCase.FeedItemId__c=fitem2.Id;
aCase.Subject='Feedpost.Title';
aCase.Reason='Function';
aCase.Type='Chatter';
aCase.Chatter_Name__c = fitem2.CreatedById;
insert aCase;
My class:
Id parentID = Feeditem.ParentId;
String groupName;
string smartBarLabel = Label.SmartBar_Custom_Label;
string IPToolLabel = Label.IP_Tool_Support_custom_label;
Map<id,CollaborationGroup> CollaborationGroupName = new Map<id,CollaborationGroup>([select id, Name from CollaborationGroup where CollaborationType='Public' and ID in :FeedId]);
Case css = new Case();
if(CollaborationGroupName.size() > 0) {
groupName = CollaborationGroupName.get(parentID).Name;
}
if(groupname!=null && groupName.equalsIgnoreCase(smartBarLabel)) {
css.RecordTypeId = ind.id;
if(SmartBarID!=null)
css.OwnerId=smartBarID;
}
else if(groupname!=null && groupname.equalsIgnoreCase(IPToolLabel)) {
css.Recordtypeid=IPind.id;
if(IPToolID!=null)
css.OwnerId=IPToolID;
}
css.Chatter_Name__c=Feedpost.CreatedById;
css.Description=FeedBody;
css.Subject=Feedpost.Title;
//css.Reason='Function';
//css.OwnerId=Label.CaseQueueOwner;
css.Type='Chatter';
css.FeedItemId__c=feedpost.id;
if(Feedpost.Title==null) css.Subject=FeedBody;
system.debug('the feedpostparent********'+css.FeedItemId__c);
csslist.add(css);
Test Class :
CollaborationGroup cg2 = new CollaborationGroup(Name='xxxx', CollaborationType='Public');
cg2.OwnerId=u1.Id;
insert cg2;
FeedItem fitem2 = new FeedItem();
fitem2.Body = 'yyyyy';
fitem2.CreatedById = u1.Id;
fitem2.ParentId = cg2.Id;
insert fitem2;
String groupnm = cg2.Name;
Case aCase = new Case();
system.assert(groupnm == 'xxxx');
system.assert(groupnm!=NULL);
aCase.OwnerId = testGroup.Id;
aCase.Recordtypeid=ind.id;
aCase.Description='FeedBody';
aCase.FeedItemId__c=fitem2.Id;
aCase.Subject='Feedpost.Title';
aCase.Reason='Function';
aCase.Type='Chatter';
aCase.Chatter_Name__c = fitem2.CreatedById;
insert aCase;
Sukhpal Singh Khaira (http://sukhpalsinghkhaira.in/)