You need to sign in to do that
Don't have an account?
Rajesh SFDC
how to increase code coverage in apex trigger?
iam getting an error :could not run tests on class because invalid type:baseConfigController
apex trigger:
===============================
trigger test on Case (before update )
{
Map<string, Schema.SobjectField> caseFields = Schema.SObjectType.Case.fields.getMap();
case caseold=trigger.old[0];
For (Case cs : Trigger.new)
{
for (string fieldName : caseFields.keySet())
{
if ( cs.get(fieldName) != Trigger.oldMap.get(cs.id).get(fieldName))
{
// cs.Track_status_history__c = 'Field ' + fieldName + ' changed from ' + string.valueOf(Trigger.oldMap.get(cs.id).get(fieldName)) + ' to ' +string.valueOf(cs.get(fieldName));
string oldvalue = string.valueOf(caseold.get(fieldName));
string newvalue= string.valueOf(cs.get(fieldName));
cs.Track_status_history__c = 'Changed '+fieldName +' From '+oldvalue +' to '+ newvalue;
break;
}
}
}
}
================================test class============================================
@isTest
public class Test_casehistory
{
public static testmethod void m1()
{
Case cs=new case();
cs.Origin='Web';
cs.Reason='other';
cs.Priority='Medium';
cs.Status='New';
cs.Type='Other';
test.startTest();
list<case> lTest1=new list<case>();
lTest1 = [SELECT Id,Origin,Reason,Priority,Status,Type FROM Case WHERE Id=:cs.Id];
update lTest1;
test.stopTest();
}
}
apex trigger:
===============================
trigger test on Case (before update )
{
Map<string, Schema.SobjectField> caseFields = Schema.SObjectType.Case.fields.getMap();
case caseold=trigger.old[0];
For (Case cs : Trigger.new)
{
for (string fieldName : caseFields.keySet())
{
if ( cs.get(fieldName) != Trigger.oldMap.get(cs.id).get(fieldName))
{
// cs.Track_status_history__c = 'Field ' + fieldName + ' changed from ' + string.valueOf(Trigger.oldMap.get(cs.id).get(fieldName)) + ' to ' +string.valueOf(cs.get(fieldName));
string oldvalue = string.valueOf(caseold.get(fieldName));
string newvalue= string.valueOf(cs.get(fieldName));
cs.Track_status_history__c = 'Changed '+fieldName +' From '+oldvalue +' to '+ newvalue;
break;
}
}
}
}
================================test class============================================
@isTest
public class Test_casehistory
{
public static testmethod void m1()
{
Case cs=new case();
cs.Origin='Web';
cs.Reason='other';
cs.Priority='Medium';
cs.Status='New';
cs.Type='Other';
test.startTest();
list<case> lTest1=new list<case>();
lTest1 = [SELECT Id,Origin,Reason,Priority,Status,Type FROM Case WHERE Id=:cs.Id];
update lTest1;
test.stopTest();
}
}
The case record you created in your test class should be inserted to fire the trigger. Please change yoiur code to something like this:
If this answers your question, please mark this as the Best Answer for this post, so that others can benefit from this post.
Thanks,
Shashank
could not run tests on class 01p90000004Rgog because:line 30,column 39:invalid type:baseConfigcontroller
01p90000004Rgog means test class url id in dis test class, i dont have line no 30,, where s dat line i done no
trigger test on Case (before update )
{
Map<string, Schema.SobjectField> caseFields = Schema.SObjectType.Case.fields.getMap();
case caseold=trigger.old[0];
For (Case cs : Trigger.new)
{
for (string fieldName : caseFields.keySet())
{
if ( cs.get(fieldName) != Trigger.oldMap.get(cs.id).get(fieldName))
{
// cs.Track_status_history__c = 'Field ' + fieldName + ' changed from ' + string.valueOf(Trigger.oldMap.get(cs.id).get(fieldName)) + ' to ' +string.valueOf(cs.get(fieldName));
string oldvalue = string.valueOf(caseold.get(fieldName)); --------------->dosnot execute its red line
string newvalue= string.valueOf(cs.get(fieldName));---------------------> dosnot execute its red line
cs.Track_status_history__c = 'Changed '+fieldName +' From '+oldvalue +' to '+ newvalue;
break;
}
}
}
}
Can you please help me with steps for pasting the code here in the format you posted ?
as Rajesh SFC has jut copy-pasted it.
Thank you in advance!