You need to sign in to do that
Don't have an account?
Brian Roberts 2
Compile Error: Variable does not exist: Please can someone point me in the right direction as I can't see my errors?
Please can someone point me in the right direction as I can't see my errors?
@isTest
private class TicketInAccrual {
public class TestData {
public Map<String, RecordType> tirtMap;
public FX5__Status__c newTicketStatus;
public FX5__Status__c TicketInAccrualStatus;
public List<FX5__Catalog_Item__c> ciList;
public List<FX5__Price_Book_Item__c> pbiList;
public String GetDefaultUOMForRecordType(String rtDeveloperName) {
if (rtDeveloperName == 'Daily_Personnel' || rtDeveloperName == 'Daily_Equipment')
return 'Day';
if (rtDeveloperName == 'Hourly_Equipment' || rtDeveloperName == 'Hourly_Personnel')
return 'Hour';
return 'Each';
}
public void ProvisionTestData(FX_UnitTestHelper.ExproJob_LocalTestData mockData) {
this.newTicketStatus = new FX5__Status__c(
Name = 'New Ticket',
FX5__SObject__c = 'Ticket__c',
Status_Developer_Name__c = 'New_Ticket');
this.TicketInAccrualStatus = new FX5__Status__c(
Name = 'Ticket in Accrual',
FX5__SObject__c = 'Ticket__c',
Status_Developer_Name__c = 'Ticket_in_Accrual');
insert this.newTicketStatus;
insert this.TicketInAccrualStatus;
this.tirtMap = new Map<String,RecordType>();
this.ciList = new List<FX5__Catalog_Item__c>();
Integer ciCount = 1;
for (RecordType tirt : [select Id,DeveloperName from RecordType where IsActive=true and SobjectType='FX5__Ticket_Item__c']) {
this.tirtMap.put(tirt.DeveloperName,tirt);
this.ciList.add(new FX5__Catalog_Item__c(
Name = String.valueOf(ciCount) + '-0135',
FX5__IsArchived__c = false,
FX5__Description__c = 'Test Item ' + String.valueOf(ciCount),
EXPRO_SAP_Plant__c = '0135',
FX5__Sequence_Number__c = ciCount,
FX5__Ticket_Item_Record_Type__c = tirt.DeveloperName,
FX5__UOM__c = GetDefaultUOMForRecordType(tirt.DeveloperName)
));
ciCount += 1;
this.ciList.add(new FX5__Catalog_Item__c(
Name = String.valueOf(ciCount) + '-0135',
FX5__IsArchived__c = false,
FX5__Description__c = 'Test Item ' + String.valueOf(ciCount),
EXPRO_SAP_Plant__c = '0135',
FX5__Sequence_Number__c = ciCount,
FX5__Ticket_Item_Record_Type__c = tirt.DeveloperName,
FX5__UOM__c = this.GetDefaultUOMForRecordType(tirt.DeveloperName)
));
ciCount += 1;
}
insert this.ciList;
Set<Id> ciIdSet = new Set<Id>();
for (FX5__Catalog_Item__c ci : ciList) {
insert (new FX5__Price_Book_Item__c(
FX5__Price_Book__c = mockData.testPriceBook.Id,
FX5__IsArchived__c = false,
FX5__Catalog_Item__c = ci.Id,
FX5__Default_Quantity__c = 0,
FX5__Price__c = 100));
ciIdSet.add(ci.Id);
}
// We want to fetch the Price Book Items back after insertion so that we get the result of all triggers that fired
this.pbiList = [
select
Id,FX5__Price_Book__c,FX5__Catalog_Item__c,FX5__IsArchived__c,FX5__Default_Quantity__c,FX5__Price__c,
FX5__Ticket_Item_Record_Type__c,FX5__Sequence_Number__c,FX5__Catalog_Item__r.FX5__Ticket_Item_Record_Type__c
from FX5__Price_Book_Item__c where FX5__Catalog_Item__c in :ciIdSet];
}
}
static testMethod void TestTicketItemSequencingForSAP() {
FX_UnitTestHelper.ExproJob_LocalTestData mockData = new FX_UnitTestHelper.ExproJob_LocalTestData();
mockData.ProvisionTestData(true);
TestData testData = new TestData();
testData.ProvisionTestData(mockData);
List<FX5__Ticket__c> tktList = FX_UnitTestHelper.CreateTickets(mockData.testJob, 2, true);
FX5__Ticket__c readyForInvTicket = tktList.get(0);
FX5__Ticket__c newTicket = tktList.get(1);
List<FX5__Ticket_Item__c> testTktItems = new List<FX5__Ticket_Item__c>();
// Add ticket items to the each mock ticket
for (FX5__Ticket__c tkt : tktList) {
for (FX5__Price_Book_Item__c pbi : testData.pbiList) {
RecordType tiRT = testData.tirtMap.get(pbi.FX5__Catalog_Item__r.FX5__Ticket_Item_Record_Type__c);
testTktItems.add(new FX5__Ticket_Item__c(
FX5__Ticket__c = tkt.Id,
FX5__Price_Book_Item__c = pbi.Id,
RecordTypeId = tiRT.Id));
}
}
insert testTktItems;
Test.startTest();
newTicket.FX5__Status__c = testData.newTicketStatus.Id;
TicketInAccrualTicket.FX5__Status__c = testData.TicketinAccrualStatus.Id;
update newTicket;
update TicketInAccrualTicket;
Test.stopTest();
List<FX5__Ticket_Item__c> newTicketItems = [select Id,FX5__Ticket__c,EXPRO_SAP_Item_Number__c from FX5__Ticket_Item__c where FX5__Ticket__c = :newTicket.Id];
// Ensure that Ticket items on the "New Ticket" items did not update EXPRO_SAP_Item_Number__c
for (FX5__Ticket_Item__c tktItem : newTicketItems) {
System.assert(tktItem.EXPRO_SAP_Item_Number__c == null, 'Expected null for EXPRO_SAP_Item_Number__c on "New Ticket" Ticket Item.');
}
List<FX5__Ticket_Item__c> TicketInAccrualTicketItems = [select Id,FX5__Ticket__c,EXPRO_SAP_Item_Number__c,Record_Type_Sort_Index__c,RecordTypeId from FX5__Ticket_Item__c where FX5__Ticket__c = :TicketInAccrualTicket.Id order by EXPRO_SAP_Item_Number__c];
System.assert(TicketInAccrualTicketItems.size() > 0);
for (Integer i=0; i < TicketInAccrualTicketItems.size(); i+=1) {
FX5__Ticket_Item__c ti = TicketInAccrualTicketItems.get(i);
System.assertEquals((i+1)*10, ti.EXPRO_SAP_Item_Number__c);
}
}
/*
* This test ensures that a Ticket that does not have a status will not crash the Ticket On After trigger and will not cause any other
* unit tests to fail that do not have a status reference.
*/
static testMethod void TestInsertTicketWithNullStatus() {
FX_UnitTestHelper.ExproJob_LocalTestData mockData = new FX_UnitTestHelper.ExproJob_LocalTestData();
mockData.ProvisionTestData(true);
RecordType ftRT = [select Id,DeveloperName from RecordType where IsActive=true and SobjectType='FX5__Ticket__c' and DeveloperName='Field_Ticket'];
FX5__Ticket__c t = new FX5__Ticket__c(
FX5__Job__c = mockData.testJob.Id,
RecordTypeId = ftRT.Id
);
Test.startTest();
insert t;
Test.stopTest();
System.assertEquals(1,([select Id from FX5__Ticket__c where FX5__Job__c = :mockData.testJob.Id]).size());
}
}
@isTest
private class TicketInAccrual {
public class TestData {
public Map<String, RecordType> tirtMap;
public FX5__Status__c newTicketStatus;
public FX5__Status__c TicketInAccrualStatus;
public List<FX5__Catalog_Item__c> ciList;
public List<FX5__Price_Book_Item__c> pbiList;
public String GetDefaultUOMForRecordType(String rtDeveloperName) {
if (rtDeveloperName == 'Daily_Personnel' || rtDeveloperName == 'Daily_Equipment')
return 'Day';
if (rtDeveloperName == 'Hourly_Equipment' || rtDeveloperName == 'Hourly_Personnel')
return 'Hour';
return 'Each';
}
public void ProvisionTestData(FX_UnitTestHelper.ExproJob_LocalTestData mockData) {
this.newTicketStatus = new FX5__Status__c(
Name = 'New Ticket',
FX5__SObject__c = 'Ticket__c',
Status_Developer_Name__c = 'New_Ticket');
this.TicketInAccrualStatus = new FX5__Status__c(
Name = 'Ticket in Accrual',
FX5__SObject__c = 'Ticket__c',
Status_Developer_Name__c = 'Ticket_in_Accrual');
insert this.newTicketStatus;
insert this.TicketInAccrualStatus;
this.tirtMap = new Map<String,RecordType>();
this.ciList = new List<FX5__Catalog_Item__c>();
Integer ciCount = 1;
for (RecordType tirt : [select Id,DeveloperName from RecordType where IsActive=true and SobjectType='FX5__Ticket_Item__c']) {
this.tirtMap.put(tirt.DeveloperName,tirt);
this.ciList.add(new FX5__Catalog_Item__c(
Name = String.valueOf(ciCount) + '-0135',
FX5__IsArchived__c = false,
FX5__Description__c = 'Test Item ' + String.valueOf(ciCount),
EXPRO_SAP_Plant__c = '0135',
FX5__Sequence_Number__c = ciCount,
FX5__Ticket_Item_Record_Type__c = tirt.DeveloperName,
FX5__UOM__c = GetDefaultUOMForRecordType(tirt.DeveloperName)
));
ciCount += 1;
this.ciList.add(new FX5__Catalog_Item__c(
Name = String.valueOf(ciCount) + '-0135',
FX5__IsArchived__c = false,
FX5__Description__c = 'Test Item ' + String.valueOf(ciCount),
EXPRO_SAP_Plant__c = '0135',
FX5__Sequence_Number__c = ciCount,
FX5__Ticket_Item_Record_Type__c = tirt.DeveloperName,
FX5__UOM__c = this.GetDefaultUOMForRecordType(tirt.DeveloperName)
));
ciCount += 1;
}
insert this.ciList;
Set<Id> ciIdSet = new Set<Id>();
for (FX5__Catalog_Item__c ci : ciList) {
insert (new FX5__Price_Book_Item__c(
FX5__Price_Book__c = mockData.testPriceBook.Id,
FX5__IsArchived__c = false,
FX5__Catalog_Item__c = ci.Id,
FX5__Default_Quantity__c = 0,
FX5__Price__c = 100));
ciIdSet.add(ci.Id);
}
// We want to fetch the Price Book Items back after insertion so that we get the result of all triggers that fired
this.pbiList = [
select
Id,FX5__Price_Book__c,FX5__Catalog_Item__c,FX5__IsArchived__c,FX5__Default_Quantity__c,FX5__Price__c,
FX5__Ticket_Item_Record_Type__c,FX5__Sequence_Number__c,FX5__Catalog_Item__r.FX5__Ticket_Item_Record_Type__c
from FX5__Price_Book_Item__c where FX5__Catalog_Item__c in :ciIdSet];
}
}
static testMethod void TestTicketItemSequencingForSAP() {
FX_UnitTestHelper.ExproJob_LocalTestData mockData = new FX_UnitTestHelper.ExproJob_LocalTestData();
mockData.ProvisionTestData(true);
TestData testData = new TestData();
testData.ProvisionTestData(mockData);
List<FX5__Ticket__c> tktList = FX_UnitTestHelper.CreateTickets(mockData.testJob, 2, true);
FX5__Ticket__c readyForInvTicket = tktList.get(0);
FX5__Ticket__c newTicket = tktList.get(1);
List<FX5__Ticket_Item__c> testTktItems = new List<FX5__Ticket_Item__c>();
// Add ticket items to the each mock ticket
for (FX5__Ticket__c tkt : tktList) {
for (FX5__Price_Book_Item__c pbi : testData.pbiList) {
RecordType tiRT = testData.tirtMap.get(pbi.FX5__Catalog_Item__r.FX5__Ticket_Item_Record_Type__c);
testTktItems.add(new FX5__Ticket_Item__c(
FX5__Ticket__c = tkt.Id,
FX5__Price_Book_Item__c = pbi.Id,
RecordTypeId = tiRT.Id));
}
}
insert testTktItems;
Test.startTest();
newTicket.FX5__Status__c = testData.newTicketStatus.Id;
TicketInAccrualTicket.FX5__Status__c = testData.TicketinAccrualStatus.Id;
update newTicket;
update TicketInAccrualTicket;
Test.stopTest();
List<FX5__Ticket_Item__c> newTicketItems = [select Id,FX5__Ticket__c,EXPRO_SAP_Item_Number__c from FX5__Ticket_Item__c where FX5__Ticket__c = :newTicket.Id];
// Ensure that Ticket items on the "New Ticket" items did not update EXPRO_SAP_Item_Number__c
for (FX5__Ticket_Item__c tktItem : newTicketItems) {
System.assert(tktItem.EXPRO_SAP_Item_Number__c == null, 'Expected null for EXPRO_SAP_Item_Number__c on "New Ticket" Ticket Item.');
}
List<FX5__Ticket_Item__c> TicketInAccrualTicketItems = [select Id,FX5__Ticket__c,EXPRO_SAP_Item_Number__c,Record_Type_Sort_Index__c,RecordTypeId from FX5__Ticket_Item__c where FX5__Ticket__c = :TicketInAccrualTicket.Id order by EXPRO_SAP_Item_Number__c];
System.assert(TicketInAccrualTicketItems.size() > 0);
for (Integer i=0; i < TicketInAccrualTicketItems.size(); i+=1) {
FX5__Ticket_Item__c ti = TicketInAccrualTicketItems.get(i);
System.assertEquals((i+1)*10, ti.EXPRO_SAP_Item_Number__c);
}
}
/*
* This test ensures that a Ticket that does not have a status will not crash the Ticket On After trigger and will not cause any other
* unit tests to fail that do not have a status reference.
*/
static testMethod void TestInsertTicketWithNullStatus() {
FX_UnitTestHelper.ExproJob_LocalTestData mockData = new FX_UnitTestHelper.ExproJob_LocalTestData();
mockData.ProvisionTestData(true);
RecordType ftRT = [select Id,DeveloperName from RecordType where IsActive=true and SobjectType='FX5__Ticket__c' and DeveloperName='Field_Ticket'];
FX5__Ticket__c t = new FX5__Ticket__c(
FX5__Job__c = mockData.testJob.Id,
RecordTypeId = ftRT.Id
);
Test.startTest();
insert t;
Test.stopTest();
System.assertEquals(1,([select Id from FX5__Ticket__c where FX5__Job__c = :mockData.testJob.Id]).size());
}
}
What is the variable in the error message? the error could be because of the scope of your class, method, or a separate scope that you've defined within one of those.
See https://salesforce.stackexchange.com/questions/40918/apex-compile-error-variable-does-not-exist that explains the same scenario.
Hope this helps you. Please mark this answer as best so that others facing the same issue will find this information useful. Thank you
the error message is
Compile Error: Variable does not exist: TicketInAccrualTicket at line 125 column 7
If i am not wrong "ciList" is the variable where you are getting that error right.
here you created an istance like
but here you don't need to use like "this."
it should just be like :- and in many lines you have used the same so please correct them according.
and also for dml statements you used the same for Ex: at 28, 29 lines so remove "this." from those lines.
If it works for you pls mark it as a best answer so that it helps others too.
Thanks.
Unfortunately this hasn't helped.
Error: Compile Error: Variable does not exist: TicketInAccrualTicket at line 125 column 7
TicketInAccrualTicket was not definied before the assignment.
TicketInAccrualTicket.FX5__Status__c = testData.TicketinAccrualStatus.Id;
Thank you but I am sorry you have lost me a little here could you explain a little moreplease?