You need to sign in to do that
Don't have an account?

Could anyone increase my code coverage please
Hi Experts,
Could anyone increase my code coverage please,its very urgent.what ever striped lines are there those lines are not covered
Class:
trigger tRIIO_Subcontractor_Client_updateContract_Scc on SCC_Client__c (after delete, after insert, after update) {
//CH02.End
set<Id> setSCCId = new set<Id>();
set<string> setClientName = new set<string>();
List<SCC__c> lstSCCUpdate = new List<SCC__c>();
//CH02.Start
List<SCC_Client__c > lstSub = new List<SCC_Client__c>();
//CH02.End
if(trigger.isInsert || trigger.isUpdate)
lstSub = trigger.new;
else
lstSub = trigger.old;
//CH02.Start
for(SCC_Client__c objSC : lstSub){
if(objSC.SCC__c != null)
setSCCId.add(objSC.SCC__c);
}
//CH02.End
map<Id,SCC__c> mapSCC = new map<Id,SCC__c>([select id, name, h_Subcontractor_Client_Name__c, Owning_Region__c,
(select id, name, Client_Names__r.Name from Subcontractor_Clients__r where Client_Names__r.Name = 'tRIIO' or Client_Names__r.Name = 'WPD') //CH01 remove - where Client_Names__r.Name = 'tRIIO' )
from SCC__c where Id =: setSCCId]);
map<Id,string> mapClientName = new map<Id,string>(); //CH01
List<SCC_Clients__c> lstClients = ([select id, Name from SCC_Clients__c where Name = 'tRIIO' or Name = 'WPD' ]); //CH01 added WPD condition
for(SCC_Clients__c objClient: lstClients){
setClientName.add(objClient.Id);
mapClientName.put(objClient.Id,objClient.Name); //CH01
}
if(trigger.isInsert || trigger.isUpdate)
//CH02.Start
for(SCC_Client__c objSub : trigger.new){
if(mapSCC.get(objSub.SCC__c).Owning_Region__c == 'Central'){
if(setClientName.Contains(objSub.Client_Names__c)){
SCC__c objSCC = mapSCC.get(objSub.SCC__c);
// system.debug('@@@ h client name: '+objSCC.h_Subcontractor_Client_Name__c);
//system.debug('@@@ Subcon client name: '+objSub.Client_Names__c);
if(objSCC.h_Subcontractor_Client_Name__c == null || objSCC.h_Subcontractor_Client_Name__c == '')
objSCC.h_Subcontractor_Client_Name__c = mapClientName.get(objSub.Client_Names__c); //CH01
else
if(!objSCC.h_Subcontractor_Client_Name__c.Contains(mapClientName.get(objSub.Client_Names__c)))
objSCC.h_Subcontractor_Client_Name__c = objSCC.h_Subcontractor_Client_Name__c + mapClientName.get(objSub.Client_Names__c); //CH01
//objSCC.h_Subcontractor_Client_Name__c = (!objSCC.h_Subcontractor_Client_Name__c.Contains(mapClientName.get(objSub.Client_Names__c))?objSCC.h_Subcontractor_Client_Name__c:'') + mapClientName.get(objSub.Client_Names__c); //CH01
system.debug('### h client name: '+objSCC.h_Subcontractor_Client_Name__c);
lstSCCUpdate.add(objSCC);
}
else if(mapSCC.get(objSub.SCC__c).Subcontractor_Clients__r.isEmpty()){
SCC__c objSCC = mapSCC.get(objSub.SCC__c);
objSCC.h_Subcontractor_Client_Name__c = '';
lstSCCUpdate.add(objSCC);
}
}
//CH02.End
}
if(trigger.isDelete)
//CH02.Start
for(SCC_Client__c objSub : trigger.old){
if(mapSCC.get(objSub.SCC__c).Owning_Region__c == 'Central')
if(mapSCC.get(objSub.SCC__c).Subcontractor_Clients__r.isEmpty()){
SCC__c objSCC = mapSCC.get(objSub.SCC__c);
objSCC.h_Subcontractor_Client_Name__c = '';
lstSCCUpdate.add(objSCC);
}
//CH02.Start
//CH01.start
else{
SCC__c objSCC = mapSCC.get(objSub.SCC__c);
boolean flgWPD = false;
boolean flgtRIIO = false;
//CH02.Start
for(SCC_Client__c obj :mapSCC.get(objSub.SCC__c).Subcontractor_Clients__r ){
if(obj.Client_Names__r.Name == 'WPD')
flgWPD = true;
if(obj.Client_Names__r.Name == 'tRIIO' )
flgtRIIO = true;
}
//CH02.End
if(mapClientName.get(objSub.Client_Names__c) == 'tRIIO' && objSCC.h_Subcontractor_Client_Name__c.contains('WPD')){
if(flgtRIIO)
objSCC.h_Subcontractor_Client_Name__c = 'WPDtRIIO';
else
objSCC.h_Subcontractor_Client_Name__c = 'WPD';
}
else if(mapClientName.get(objSub.Client_Names__c) == 'WPD' && objSCC.h_Subcontractor_Client_Name__c.contains('tRIIO')){
if(flgWPD)
objSCC.h_Subcontractor_Client_Name__c = 'WPDtRIIO';
else
objSCC.h_Subcontractor_Client_Name__c = 'tRIIO';
}
lstSCCUpdate.add(objSCC);
} //CH01.end
}
if(!lstSCCUpdate.isEmpty()){
List<SCC__c> lstSCC = new List<SCC__c>();
Set<SCC__c> setSCC = new Set<SCC__c>();
for(SCC__c obj:lstSCCUpdate){
if(!setSCC.contains(obj)) lstSCC.add(obj);
setSCC.add(obj);
}
//update lstSCCUpdate;
update lstSCC;
}
}
@isTest
private class tRIIO_Subcont_Client_updateCont_Scc_test {
static testMethod void myUnitTest(){
SCC_Clients__c testSclient = new SCC_Clients__c(Name = 'tRIIO', Owning_Region__c = 'Central');
insert testSclient;
SCC_Clients__c testSclient1 = new SCC_Clients__c(Name = 'test scc client', Owning_Region__c = 'Central');
insert testSclient1;
SCC__c testScc = new SCC__c(Name = 'test SCC', Contact_Name__c = 'test Contact name',Location__c = 'test location',
Street__c = 'test street', Town__c = 'test town', Number_of_Employees__c = 'Less than 5 employees',
Area_Covered__c = 'Central', Owning_Region__c = 'Central');
insert testScc;
//CH01.Start
SCC_Client__c testSubClient = new SCC_Client__c(Name = 'test Subcontractor Client',
Client_Names__c = testSclient.Id , SCC__c = testScc.Id);
insert testSubClient;
testSubClient.Client_Names__c = testSclient1.Id;
update testSubClient;
delete testSubClient;
//CH01.End
}
}
Could anyone increase my code coverage please,its very urgent.what ever striped lines are there those lines are not covered
Class:
trigger tRIIO_Subcontractor_Client_updateContract_Scc on SCC_Client__c (after delete, after insert, after update) {
//CH02.End
set<Id> setSCCId = new set<Id>();
set<string> setClientName = new set<string>();
List<SCC__c> lstSCCUpdate = new List<SCC__c>();
//CH02.Start
List<SCC_Client__c > lstSub = new List<SCC_Client__c>();
//CH02.End
if(trigger.isInsert || trigger.isUpdate)
lstSub = trigger.new;
else
lstSub = trigger.old;
//CH02.Start
for(SCC_Client__c objSC : lstSub){
if(objSC.SCC__c != null)
setSCCId.add(objSC.SCC__c);
}
//CH02.End
map<Id,SCC__c> mapSCC = new map<Id,SCC__c>([select id, name, h_Subcontractor_Client_Name__c, Owning_Region__c,
(select id, name, Client_Names__r.Name from Subcontractor_Clients__r where Client_Names__r.Name = 'tRIIO' or Client_Names__r.Name = 'WPD') //CH01 remove - where Client_Names__r.Name = 'tRIIO' )
from SCC__c where Id =: setSCCId]);
map<Id,string> mapClientName = new map<Id,string>(); //CH01
List<SCC_Clients__c> lstClients = ([select id, Name from SCC_Clients__c where Name = 'tRIIO' or Name = 'WPD' ]); //CH01 added WPD condition
for(SCC_Clients__c objClient: lstClients){
setClientName.add(objClient.Id);
mapClientName.put(objClient.Id,objClient.Name); //CH01
}
if(trigger.isInsert || trigger.isUpdate)
//CH02.Start
for(SCC_Client__c objSub : trigger.new){
if(mapSCC.get(objSub.SCC__c).Owning_Region__c == 'Central'){
if(setClientName.Contains(objSub.Client_Names__c)){
SCC__c objSCC = mapSCC.get(objSub.SCC__c);
// system.debug('@@@ h client name: '+objSCC.h_Subcontractor_Client_Name__c);
//system.debug('@@@ Subcon client name: '+objSub.Client_Names__c);
if(objSCC.h_Subcontractor_Client_Name__c == null || objSCC.h_Subcontractor_Client_Name__c == '')
objSCC.h_Subcontractor_Client_Name__c = mapClientName.get(objSub.Client_Names__c); //CH01
else
if(!objSCC.h_Subcontractor_Client_Name__c.Contains(mapClientName.get(objSub.Client_Names__c)))
objSCC.h_Subcontractor_Client_Name__c = objSCC.h_Subcontractor_Client_Name__c + mapClientName.get(objSub.Client_Names__c); //CH01
//objSCC.h_Subcontractor_Client_Name__c = (!objSCC.h_Subcontractor_Client_Name__c.Contains(mapClientName.get(objSub.Client_Names__c))?objSCC.h_Subcontractor_Client_Name__c:'') + mapClientName.get(objSub.Client_Names__c); //CH01
system.debug('### h client name: '+objSCC.h_Subcontractor_Client_Name__c);
lstSCCUpdate.add(objSCC);
}
else if(mapSCC.get(objSub.SCC__c).Subcontractor_Clients__r.isEmpty()){
SCC__c objSCC = mapSCC.get(objSub.SCC__c);
objSCC.h_Subcontractor_Client_Name__c = '';
lstSCCUpdate.add(objSCC);
}
}
//CH02.End
}
if(trigger.isDelete)
//CH02.Start
for(SCC_Client__c objSub : trigger.old){
if(mapSCC.get(objSub.SCC__c).Owning_Region__c == 'Central')
if(mapSCC.get(objSub.SCC__c).Subcontractor_Clients__r.isEmpty()){
SCC__c objSCC = mapSCC.get(objSub.SCC__c);
objSCC.h_Subcontractor_Client_Name__c = '';
lstSCCUpdate.add(objSCC);
}
//CH02.Start
//CH01.start
else{
SCC__c objSCC = mapSCC.get(objSub.SCC__c);
boolean flgWPD = false;
boolean flgtRIIO = false;
//CH02.Start
for(SCC_Client__c obj :mapSCC.get(objSub.SCC__c).Subcontractor_Clients__r ){
if(obj.Client_Names__r.Name == 'WPD')
flgWPD = true;
if(obj.Client_Names__r.Name == 'tRIIO' )
flgtRIIO = true;
}
//CH02.End
if(mapClientName.get(objSub.Client_Names__c) == 'tRIIO' && objSCC.h_Subcontractor_Client_Name__c.contains('WPD')){
if(flgtRIIO)
objSCC.h_Subcontractor_Client_Name__c = 'WPDtRIIO';
else
objSCC.h_Subcontractor_Client_Name__c = 'WPD';
}
else if(mapClientName.get(objSub.Client_Names__c) == 'WPD' && objSCC.h_Subcontractor_Client_Name__c.contains('tRIIO')){
if(flgWPD)
objSCC.h_Subcontractor_Client_Name__c = 'WPDtRIIO';
else
objSCC.h_Subcontractor_Client_Name__c = 'tRIIO';
}
lstSCCUpdate.add(objSCC);
} //CH01.end
}
if(!lstSCCUpdate.isEmpty()){
List<SCC__c> lstSCC = new List<SCC__c>();
Set<SCC__c> setSCC = new Set<SCC__c>();
for(SCC__c obj:lstSCCUpdate){
if(!setSCC.contains(obj)) lstSCC.add(obj);
setSCC.add(obj);
}
//update lstSCCUpdate;
update lstSCC;
}
}
@isTest
private class tRIIO_Subcont_Client_updateCont_Scc_test {
static testMethod void myUnitTest(){
SCC_Clients__c testSclient = new SCC_Clients__c(Name = 'tRIIO', Owning_Region__c = 'Central');
insert testSclient;
SCC_Clients__c testSclient1 = new SCC_Clients__c(Name = 'test scc client', Owning_Region__c = 'Central');
insert testSclient1;
SCC__c testScc = new SCC__c(Name = 'test SCC', Contact_Name__c = 'test Contact name',Location__c = 'test location',
Street__c = 'test street', Town__c = 'test town', Number_of_Employees__c = 'Less than 5 employees',
Area_Covered__c = 'Central', Owning_Region__c = 'Central');
insert testScc;
//CH01.Start
SCC_Client__c testSubClient = new SCC_Client__c(Name = 'test Subcontractor Client',
Client_Names__c = testSclient.Id , SCC__c = testScc.Id);
insert testSubClient;
testSubClient.Client_Names__c = testSclient1.Id;
update testSubClient;
delete testSubClient;
//CH01.End
}
}
check it once the code
@istest
global class s2stest{
static testMethod void testMe() {
// create a new email and envelope object
Messaging.InboundEmail email = new Messaging.InboundEmail() ;
Messaging.InboundEnvelope env = new Messaging.InboundEnvelope();
// setup the data for the email
email.subject = 'Test Job Applicant';
email.fromname = 'FirstName LastName';
env.fromAddress = 'someaddress@email.com';
// call the email service class and test it with the data in the testMethod
S2S_Notes_Inbound_Email_Handler Process = new S2S_Notes_Inbound_Email_Handler();
Process.handleInboundEmail(email, env);
string text=new string(recordname='name',objectname='hi',title='check')
insert text;
Note note = new Note(parentid=text.id, Title = title,body = body);
// find the attachment
Note noteExistings = [select id from Note where parentid=:text.id and Title = :Title];
System.assertEquals(a.id,'textfile.txt'); }
}
All Answers
Could you please post your test class so that I can help to fix your isssue .How much coverage you have and what exactly your issue .Really it is very difficult to write test class with knowing the object structue and mandatory fileds in each .
Please check the link below it will give you most of the tips and tricks on test class .
http://https://developer.salesforce.com/forums/ForumsMain?id=906F0000000BKUCIA4
Test class:(70%)
@isTest
private class tRIIO_Subcont_Client_updateCont_Scc_test {
static testMethod void myUnitTest(){
SCC_Clients__c testSclient = new SCC_Clients__c(Name = 'tRIIO', Owning_Region__c = 'Central');
insert testSclient;
SCC_Clients__c testSclient1 = new SCC_Clients__c(Name = 'test scc client', Owning_Region__c = 'Central');
insert testSclient1;
SCC__c testScc = new SCC__c(Name = 'test SCC', Contact_Name__c = 'test Contact name',Location__c = 'test location',
Street__c = 'test street', Town__c = 'test town', Number_of_Employees__c = 'Less than 5 employees',
Area_Covered__c = 'Central', Owning_Region__c = 'Central');
insert testScc;
//CH01.Start
SCC_Client__c testSubClient = new SCC_Client__c(Name = 'test Subcontractor Client',
Client_Names__c = testSclient.Id , SCC__c = testScc.Id);
insert testSubClient;
testSubClient.Client_Names__c = testSclient1.Id;
update testSubClient;
delete testSubClient;
//CH01.End
}
}
Looking at that test code, the main issue I see is that you are not doing any System.Assert based on what you are doing.
Its all well and good getting code coverage, but if you are not checking that your code actually works, then your tests are pointless.
You need to look at your code and write down every action that could happen, all the results that you expect, then test each one of those.
in a trigger which area part not covered just check it and paste it here can i do modification
Thanks for the reply i completed this code coverage, i have one more class which im not able do code coverage could you do it please. these are the striped lines which are not covered
global class S2S_Notes_Inbound_Email_Handler implements Messaging.InboundEmailHandler {
/**
handleInboundEmail() - Processes the email & extracts body, subject & Attachments.
**/
global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email, Messaging.InboundEnvelope envelope) {
Messaging.InboundEmailResult result = new Messaging.InboundEmailresult();
//result.success = true;
//result.message = 'Your request has been processed.';
//return result;
Map<String, String> allObjectsMap = new Map<String,String>{'Accreditation'=>'Accreditation__c','SCCAccreditations'=>'SCC_Accreditations__c','SCCClient'=>'SCC_Clients__c'
,'SCCS14'=>'SCC_C34__c','SCCSentEmailHistory'=>'SCC_Sent_Email_History__c','SubcontractorClient'=>'Subcontractor_Client__c','SubcontractorPerformanceReview'=>'','SubContractRegister'=>'SCC__c','SubcontractorAudits'=>'Subcontractor_Audits__c'};
try{
All_ConnectionHelpler.batchRunning = true;
String body = email.plainTextBody;
String subject = email.subject;
List<String> lstSub = subject.split('#@#',-5);
String recordname = lstSub[1];
String objectName = lstSub[2];String title = lstSub[3];if(allObjectsMap.keySet().contains(objectName))
objectName = allObjectsMap.get(objectName);
String query = 'select id from '+objectName+' where name =\''+recordname+'\'';
sObject s = Database.query(query);
Note note = new Note(parentid=s.id, Title = title,body = body);
Note[] noteExistings = [select id from Note where parentid=:s.id and Title = :Title];
if(noteExistings.size()>0){
note = noteExistings[0];
note.body=body;
//note.id = noteExistings[0].id;
}
upsert note;}catch(Exception e){
//result.success = false;
//result.message = 'Error'+e.getMessage();
return result;
}
//result.success = false;
//result.message = 'YES'+note.id;
return result;}
}
this requirement i can provide link pls see below,it will help to you
http://blog.jeffdouglas.com/2010/03/12/writing-an-inbound-email-service-for-salesforce-com/
http://sfdcsrini.blogspot.com/2014/11/inbound-email-service-in-salesforce.html
Hope this helps! Mark it as solution if this solves your problem.
Regards
Eswar Prasad.
I tried it from here onwards code is not moving.
objectName = allObjectsMap.get(objectName);
String query = 'select id from '+objectName+' where name =\''+recordname+'\'';
sObject s = Database.query(query);
Note note = new Note(parentid=s.id, Title = title,body = body);
Note[] noteExistings = [select id from Note where parentid=:s.id and Title = :Title];
if(noteExistings.size()>0){
note = noteExistings[0];
note.body=body;
check it once the code
@istest
global class s2stest{
static testMethod void testMe() {
// create a new email and envelope object
Messaging.InboundEmail email = new Messaging.InboundEmail() ;
Messaging.InboundEnvelope env = new Messaging.InboundEnvelope();
// setup the data for the email
email.subject = 'Test Job Applicant';
email.fromname = 'FirstName LastName';
env.fromAddress = 'someaddress@email.com';
// call the email service class and test it with the data in the testMethod
S2S_Notes_Inbound_Email_Handler Process = new S2S_Notes_Inbound_Email_Handler();
Process.handleInboundEmail(email, env);
string text=new string(recordname='name',objectname='hi',title='check')
insert text;
Note note = new Note(parentid=text.id, Title = title,body = body);
// find the attachment
Note noteExistings = [select id from Note where parentid=:text.id and Title = :Title];
System.assertEquals(a.id,'textfile.txt'); }
}
here showing recordname as well as title, could you check and tell me pelase, i deployed the code but showing error "Recordname","Title"