You need to sign in to do that
Don't have an account?
Salesforce_user007
Test class for apex triger.
i hav written a trigger ,can anyone help to write the test class:
trigger Industry on Account (after update) {
List<Account> clientList = new List<Account>();
for(Account a: Trigger.New){
if((Trigger.oldMap.get(a.Id).Indus<> Trigger.newMap.get(a.Id).Indus ||
(Trigger.oldMap.get(a.Id).S__c <> Trigger.newMap.get(a.Id).S__c)
{
clientList.add(a);
}
}
if(!clientList.isEmpty()){
updateIndustry.industrySector(clientList);
}
}
Thanks.
Below is my test class ,i am getting 0% test coverage.Please let me know where i went wrong:
@isTest
private class TestIndustry
{
static testMethod void myUnitTest()
{
Account c=new Account();
c.Industry='Final';
c.S__c='aaa';
update c;
}
}
Hi,
Try this code...
Hi,
Still i am getting 0% code coverage.
Hi,
Try this
@isTest
Private class Industry1{
static testMethod void AccountExt_Test1()
{
Account acc = new Account();
acc.name='test';
acc.Industry='Banking';
insert acc;
acc.name='test1';
acc.Industry='Biotechnology';
update acc;
}}
Regards,
Rajesh.
Hi Rajesh ,
Thanks for ur reply ...... but still 0% code coverage....
Hi
But for me showing 100% code coverage.Let me know r u running in Eclipse or User Interface.
Regards,
Rajesh
Hi
Goto->setup->Develop->Apex Classes->select ur test class->Run Test.
When u click on Run test search ur trigger and click the percentage beside trigger,then it will show some lines are blue and some red lines.which means red lines that are not covered.
Let me know if any query.
Regards,
Rajesh.
@SRS8 i got your point but due to some issue i am not able to view the Debug log for test class.
Hi
No need debug log u just follow what i have post previously.See ur tiggger with 100%.
Regards,
Rajesh.
I am getting 0% test coverage.
Hi
I surprised same code for me showing 100% but to u it show 0%.
Did u follow this Goto->setup->Develop->Apex Classes->select ur test class->Run Test.and search ur trigger,can u send the screen shot after u click Run Test of ur test class.
Regards,
Rajesh.
I am getting "test failure" Error message :line 4, column 9: Method does not exist or incorrect signature: [GrantAccess].grantAccess(LIST<Project__c>).
But this particular field is not related to the object that i am reffering for the trigger test class.I am not sure y i am getting this error??
Thanks.
Hi
Could u post ur updated trigger and test class.
Regards,
Rajesh.
@Rajesh
I have sent update trigger and test class to you .Please check ur Private Message.
Thanks.
Hi
Try this , if officer is picklist datatype then put the picklist two different value in it.
@isTest
private class TestupdateClientIndustrySector
{
static testMethod void myupdateClientIndustrySector()
{
Account acc=new Account();
acc.Industry='Financial';
acc.Sub_Industry__c ='Finance';
acc.Sector__c ='Companies';
acc.Short_Description__c ='Hello';
acc.Sub_Sector__c='';
acc.Name = 'Venture';
acc.Officer__='test';
insert acc;
acc.Industry='Industrials';
acc.Sub_Industry__c ='Industrials';
acc.Sector__c ='Electronics';
acc.Officer__='test11';
update acc;
}
}
Regards,
Rajesh.
Hi,
Still i am getting 0% test coverage.
Thanks.
Hi
Did u get any errors.
Let me know.
Regards,
Rajesh.
Same error as i have mentioned before:
"test failure" Error message :line 4, column 9: Method does not exist or incorrect signature: [GrantAccess].grantAccess(LIST<Project__c>).
Hi
U added some classes w.r.t methods in this plese check that methods are exist are or not.And I change the trigger in blue color which is correct or not let u check that. Then Run ur test class.
trigger updateIndustry on Account (after update) {
List<Account> clientList = new List<Account>()
;
list<Account> updatedOfficrsList = new List<Account>();
// to update the related Deals on update of the Industry/Sector fields on Account
for(Account cln: Trigger.New){
if((Trigger.oldMap.get(cln.Id).Industry <> Trigger.newMap.get(cln.Id).Industry) ||
(Trigger.oldMap.get(cln.Id).Sub_Industry__c <> Trigger.newMap.get(cln.Id).Sub_Industry__c) ||
(Trigger.oldMap.get(cln.Id).Sector__c <> Trigger.newMap.get(cln.Id).Sector__c) ||
(Trigger.oldMap.get(cln.Id).Sub_Sector__c <> Trigger.newMap.get(cln.Id).Sub_Sector__c)) {
clientList.add(cln);
}
}
if(!clientList.isEmpty()){
//to update the related Deals fields
updateIndustry.industrySectorUpdate(clientList);
}
// on change of Client's Officer
for(Account client: Trigger.New){
if(Trigger.oldMap.get(client.Id).Officer__c <> Trigger.newMap.get(client.Id).Officer__c ||
Trigger.oldMap.get(client.Id).Officer_2__c <> Trigger.newMap.get(client.Id).Officer_2__c ){
updatedOfficrsList.add(client);
}
if(updatedOfficrsList.size() > 0){
DealTeamInsertion.updateOfficerChange(updatedOfficrsList);
}
}
}
Regards,
Rajesh.
still 0% coverage..
Hi
I tried with ur triggger that u sent getting the 100% code coverage but u didn't get I don't know why and try to see the dependencies of the trigger by clicking on Show Dependencies and try to solve that error.U will get. :)
Regards,
Rajesh.