You need to sign in to do that
Don't have an account?
ST_SFDC
// method submit the case
public PageReference submitCase() {
try {
// Specify DML options to ensure the assignment rules are executed
Database.DMLOptions dmlOpts = new Database.DMLOptions();
dmlOpts.assignmentRuleHeader.useDefaultRule = true;
c.setOptions(dmlOpts);
c.SuppliedName = username;
c.SuppliedEmail = useremail;
c.Market__c = market;
c.Boss_Region__c = region;
c.Case_CC_List__c = CCuser;
ccAddresses = CCuser.split(','); // capture multiple CCed email list
if(productType=='Manage'){
Id mngRcdTypeId = Schema.SObjectType.Case.getRecordTypeInfosByName().get('Manage').getRecordTypeId();
c.RecordTypeId = mngRcdTypeId; // RT = Manage
}
else if(ReqType =='Salesforce Support' || productTypeRadia=='SalesForce Related Issue') {
Id sfsRcdTypeId = Schema.SObjectType.Case.getRecordTypeInfosByName().get('Salesforce Support').getRecordTypeId();
c.RecordTypeId = sfsRcdTypeId; // RT= SF Support
}
else if(ReqType =='New Feature Request'){
Id enblmtRcdTypeId = Schema.SObjectType.Case.getRecordTypeInfosByName().get('Enablement').getRecordTypeId();
c.RecordTypeId = enblmtRcdTypeId; // RT = Enablement
}
if((productType=='XBP' && (productTypeRadia=='Radia Related Issue' ||productTypeRadia=='Business Question / Help'))||productType=='Slack'){
sendEmail(); // send email
}
INSERT c;
//Attachment Start
attachment.OwnerId = UserInfo.getUserId();
attachment.ParentId = c.id; // the record the file is attached to
attachment.IsPrivate = false;
system.debug('starting try block ++++++++++++++');
try {
insert attachment;
} catch (DMLException e) {
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Error uploading attachment'));
// return null;
}
system.debug('Ending try block ++++++++++++++');
PageReference redirectPage = Page.thanks;
redirectPage.setRedirect(true);
return redirectPage;
} catch (Exception e) {
ApexPages.addMessages(e);
return null;
}
}
}
Apex Test Class: Not able to increase code coverage of this apex class more then 73%
// method submit the case
public PageReference submitCase() {
try {
// Specify DML options to ensure the assignment rules are executed
Database.DMLOptions dmlOpts = new Database.DMLOptions();
dmlOpts.assignmentRuleHeader.useDefaultRule = true;
c.setOptions(dmlOpts);
c.SuppliedName = username;
c.SuppliedEmail = useremail;
c.Market__c = market;
c.Boss_Region__c = region;
c.Case_CC_List__c = CCuser;
ccAddresses = CCuser.split(','); // capture multiple CCed email list
if(productType=='Manage'){
Id mngRcdTypeId = Schema.SObjectType.Case.getRecordTypeInfosByName().get('Manage').getRecordTypeId();
c.RecordTypeId = mngRcdTypeId; // RT = Manage
}
else if(ReqType =='Salesforce Support' || productTypeRadia=='SalesForce Related Issue') {
Id sfsRcdTypeId = Schema.SObjectType.Case.getRecordTypeInfosByName().get('Salesforce Support').getRecordTypeId();
c.RecordTypeId = sfsRcdTypeId; // RT= SF Support
}
else if(ReqType =='New Feature Request'){
Id enblmtRcdTypeId = Schema.SObjectType.Case.getRecordTypeInfosByName().get('Enablement').getRecordTypeId();
c.RecordTypeId = enblmtRcdTypeId; // RT = Enablement
}
if((productType=='XBP' && (productTypeRadia=='Radia Related Issue' ||productTypeRadia=='Business Question / Help'))||productType=='Slack'){
sendEmail(); // send email
}
INSERT c;
//Attachment Start
attachment.OwnerId = UserInfo.getUserId();
attachment.ParentId = c.id; // the record the file is attached to
attachment.IsPrivate = false;
system.debug('starting try block ++++++++++++++');
try {
insert attachment;
} catch (DMLException e) {
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Error uploading attachment'));
// return null;
}
system.debug('Ending try block ++++++++++++++');
PageReference redirectPage = Page.thanks;
redirectPage.setRedirect(true);
return redirectPage;
} catch (Exception e) {
ApexPages.addMessages(e);
return null;
}
}
}
please show how does your test class looks like? What lines you're not able to cover?
I am not able to cover attachement part and case Insertion.
*****************
@isTest
private class SubmitCaseBOSSControllerTest {
private static testMethod void test() {
SubmitCaseBOSSController sc = new SubmitCaseBOSSController();
sc.sflist= true;
sc.newfeaturelist = false;
sc.ProductTypeBool= true;
sc.ProductTypeXBPBool = false;
sc.ProductTypeBool= false;
sc.ProductTypeXBPBool = true;
sc.newfeaturelist =false;
sc.ProductTypeMngBool = false;
// sc.ccAddresses ='abc@abc.com';
// system.assertEquals(ccaddress.size(), '2');
sc.setsflist(true);
sc.getsflist();
sc.setnewfeaturelist(true);
sc.getnewfeaturelist();
sc.setProductTypeBool(true);
sc.getProductTypeBool();
sc.setProductTypeXBPBool(true);
sc.getProductTypeXBPBool();
sc.setProductTypeMngBool(true);
sc.getProductTypeMngBool();
sc.setslackBool(true);
sc.getslackBool();
sc.selectvalue();
sc.selectvalueProductType();
sc.sendEmail();
sc.setselectvalue();
sc.setselectvalueProductType();
sc.submitCase();
sc.response ='hello';
sc.ReqTypeDependent ='test';
System.assertEquals(sc.ReqTypeDependent, 'test');
sc.productTypeRadia ='test1';
System.assertEquals(sc.productTypeRadia, 'test1');
sc.fileName ='test1';
System.assertEquals(sc.fileName, 'test1');
sc.priority ='test1';
System.assertEquals(sc.priority, 'test1');
sc.ReqTypMng ='test1';
System.assertEquals(sc.ReqTypMng, 'test1');
// sc.fileBody ='test1';
//System.assertEquals(sc.fileBody, 'test1');
Profile p = [SELECT Id FROM Profile WHERE Name='System Administrator'];
User us = new User(Alias = 'newUs', Email='newuser@user.com',
EmailEncodingKey='UTF-8',FirstName='Test', LastName='TestBoss', LanguageLocaleKey='en_US',
LocaleSidKey='en_US', ProfileId = p.Id,
TimeZoneSidKey='America/Los_Angeles', UserName='Test@user.com.boss');
insert us;
///for Attachment//
Case cs=new Case();
cs.SuppliedName = us.Name;
cs.SuppliedEmail = us.Email;
cs.Market__c = 'market';
cs.Region__c = 'region';
cs.RecordTypeId = '012i0000001E2OUAA0';
cs.product_list_boss__c = 'Salesforce';
cs.Request_Type__c = 'Salesforce Support';
insert cs;
Blob fileBody=Blob.valueOf('Unit Test Attachment Body');
Attachment attachment=new Attachment();
attachment.Name='Unit Test Attachment';
attachment.body=fileBody;
attachment.parentId=cs.id;
insert attachment;
sc.attachment = attachment;
//Attachment Ends//
List<Attachment> attachments=[select id, name from Attachment where parent.id=:cs.id];
System.assertEquals(1, attachments.size());
test.startTest();
Case cs1=new Case();
cs1.SuppliedName = us.Name;
cs1.SuppliedEmail = us.Email;
cs1.Market__c = 'market';
cs1.Region__c = 'region';
Id sfRcdTypeId = Schema.SObjectType.Case.getRecordTypeInfosByName().get('Salesforce Support').getRecordTypeId();
cs1.RecordTypeId = sfRcdTypeId;
cs1.Request_Type__c = 'Salesforce Support';
cs1.Product__c = 'Salesforce';
insert cs1;
Blob fileBody1=Blob.valueOf('Unit Test Attachment Body');
Attachment attachment1=new Attachment();
attachment1.Name='Unit Test Attachment';
attachment1.body=fileBody1;
attachment1.parentId=cs1.id;
insert attachment1;
sc.attachment = attachment1;
List<Attachment> attachments1=[select id, name from Attachment where parent.id=:cs1.id];
System.assertEquals(1, attachments1.size());
List<SelectOption> selOpts=sc.regions;
//System.assertEquals(selOpts, 'NA',);
sc.RadiaProduct='test11';
List<SelectOption> selOpts2=sc.ProductList;
List<SelectOption> selOpts3=sc.MarketList;
List<SelectOption> selOpts4=sc.RequestTypeList;
List<SelectOption> selOpts5=sc.ReqTypeDependentList;
List<SelectOption> selOpts6=sc.RequestTypeMngList;
List<SelectOption> selOpts7=sc.PriorityLst;
List<SelectOption> selOpts8=sc.RadiaRequestTypeList;
cs1.Region__c = 'EMEA';
update cs1;
PageReference pageRef = Page.thanks;
pageRef.getParameters().put('id',String.valueOf(cs1.Id));
Test.setCurrentPage(pageRef);
test.stopTest();
}
}