Hi I am try to deactivate trigger in production through change sets.
First i deactivate trigger in sandbox and try to deploy that trigger to production.But i face some issues like.
But test class of that trigger raise a issue like.Even I put assertion statement in comments.
System.AssertException: Assertion Failed: Expected: 35, Actual: null Stack Trace: Class.TestDeviceUpdate.testStandardUseropp: line 45, column 1
Any help is appreciated.
My Apex trigger
trigger DeviceUpdate on BI_Device__c (before insert,before update)
{
if(Trigger.isBefore && trigger.isInsert || Trigger.isBefore && trigger.isUpdate )
{
DeviceMapping.deviceUpdate(Trigger.New);
}
}
Apex Class
public class DeviceMapping
{
public Static void deviceUpdate (List<BI_Device__c> Deviceids)
{
List<String> s= new List<String> ();
for(BI_Device__c b:deviceids)
{
s.Add(b.Azuga_Customer_ID__c);
}
List<Account> contactListToDelete = [select id,No_of_Devices_activated_in_Portal__c,Azuga_Customer_ID__c from account where Azuga_Customer_ID__c IN : s];
for(Account a:contactListToDelete)
{
for(BI_Device__c bi: deviceids)
{
if(bi.Azuga_Customer_ID__c==a.Azuga_Customer_ID__c)
{
a.No_of_Devices_activated_in_Portal__c=bi.No_of_Devices_activated_in_Portal__c;
}
}
Upsert a;
}
/*List<Account> contactListToDelete = [select id from account where Azuga_Customer_ID__c IN : Deviceids];
Map<Id, account> opMap = new Map<Id, account>();
for(account o : contactListToDelete)
{
opMap.put(o.Id,o);
} */
//Delete if list is not empty
}
}
My test class
@isTest
public class TestDeviceUpdate
{
static testMethod void testStandardUseropp()
{
// Create a new user with the Standard User profile
Profile standardProf = [select id from profile where name='Standard User'];
User su = new User(alias = 'standt', email='[email protected]',
emailencodingkey='UTF-8',FirstName='opp', lastname='testing', languagelocalekey='en_US',
localesidkey='en_US', profileid = standardProf.Id,
timezonesidkey='America/Los_Angeles', username='[email protected]');
// Switch current user to Standard User
System.runAs(su)
{
List<Account> Accounts = new List<Account>{};
for(Integer i = 0; i < 50; i++)
{
Account a = new Account(Name='Test'+ i,Azuga_Customer_ID__c='123'+i);
Accounts.add(a);
}
insert Accounts;
List<BI_Device__c> Bidevices = new List<BI_Device__c>{};
for(Integer i = 0; i < 50; i++)
{
BI_Device__c b = new BI_Device__c(Name='Test'+ i,Azuga_Customer_ID__c='123'+i,
No_of_Devices_activated_in_Portal__c=35);
Bidevices.add(b);
}
test.startTest();
// Insert the Account records that cause the trigger to execute.
insert Bidevices;
// Stop the test, this changes limit context back to test from trigger.
test.stopTest();
// Query the database for the newly inserted records.
List<Account> insertedAccounts = [SELECT Name,No_of_Devices_activated_in_Portal__c,
Azuga_Customer_ID__c FROM Account
WHERE Id IN :Accounts];
// Assert that the Description fields contains the proper value now.
/*for(Account l : insertedAccounts)
{
System.assertEquals(null,l.No_of_Devices_activated_in_Portal__c);
}*/
}
}
}