So Im making an Apex class that I want to push to production that will change the record type of an object, to a different record type.
Here is the class below:
public class removeclassy {
List<Campaign> camplist = [SELECT Name,id FROM Campaign WHERE RecordTypeid = '01215000001YqO9AAK'];
public void DestroyCampClassy()
{
for(Campaign camp : camplist)
{
camp.RecordTypeId ='01215000001DWqoAAG';
if(camp.RecordTypeId == '01215000001DWqoAAG')
{
System.debug('record type changed on this record: '+ camp.Name);
update camp;
}
}
System.debug('Loop finished');
}
}
And here is the Test method that i want to pair with it.
@IsTest static void testCamp()
{
Campaign camp = new Campaign();
camp.Name = 'test';
camp.RecordTypeId = '01215000001YqO9AAK';
Test.startTest();
insert camp;
Test.stopTest();
removeclassy rem = new removeclassy();
rem.DestroyCampClassy();
system.assertEquals('01215000001DWqoAAG', camp.RecordTypeId);
}
The problem that I am encountering is that the test object that I create doesn't get its record type changed when I call the class. The class itself does an SOQL query that should get all the objects with that objects specific record type in order to change it to another. But for some reason the DestroyCampClassy method does not change this. Any thoughts?
update camplist;
. Using an implementation of the Unit of Work pattern (like fflib_SObjectUnitOfWork, trailhead module here) is another option, but don't feel a need to drop everything and start using that now.