You need to sign in to do that
Don't have an account?

Test class issue
Hi every one,
i wrote trigger on glovia OM manage package.Now i am writting test class for those trigger then i am getting error like this-
System.DmlException: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, System policy record is missing for glovia OM Application or you may not have access to it. Please contact your system administrator.: []
Trigger-
trigger TreatmentPrice on Treatments__c (After Insert,After Update,before Delete)
{
//Limit the size of list by using Sets which do not contain duplicate elements
set<ID> SQIds = new set<ID>();
set<ID> PTIDs=new set<ID>();
set<string> PFamily=new set<string>();
//When adding new create invoice or updating existing quote
if(trigger.isInsert || trigger.isUpdate)
{
for(Treatments__c p : trigger.new)
{
SQIds.add(p.Sales_Quote_Id__c);
PTIDs.add(p.Treatment_Name__c);
}
//Map will contain one quote Id to one Count value(no of Invoice)
map<Id,Decimal> SalesQuoteMap = new map<Id,Decimal>();
map<Id,Decimal> SalesQuoteMap1 = new map<Id,Decimal>();
try{
List<Treatments__c > PF=[select id,Treatment_Name__c from Treatments__c where Sales_Quote_Id__c IN :SQIds AND Treatment_Name__c IN :PTIDs ];
//use group by to have a single appointment Id with a single sum value
for(AggregateResult q : [select Sales_Quote_Id__c,SUM(Total_Price__c) from Treatments__c where Sales_Quote_Id__c IN :SQIds group by Sales_Quote_Id__c])
{
SalesQuoteMap.put((Id)q.get('Sales_Quote_Id__c'),(Double)q.get('expr0'));
}
/*for(AggregateResult q : [select Sales_Quote_Id__c,SUM(Credit_Adjustments__c) from Treatments__c where Sales_Quote_Id__c IN :SQIds group by Sales_Quote_Id__c])
{
SalesQuoteMap1.put((Id)q.get('Sales_Quote_Id__c'),(Double)q.get('expr0'));
}*/
List<gii__SalesQuote__c> SalesQuoteToUpdate = new List<gii__SalesQuote__c>();
//Run the for loop on Sales Quote using the non-duplicate set of Sales quote Ids
for(gii__SalesQuote__c o : [Select Id,Treatment_Discount__c,Estimated_cost__c from gii__SalesQuote__c where Id IN :SQIds])
{
Double QuoteCount = SalesQuoteMap.get(o.Id);
//Double Discount = SalesQuoteMap1.get(o.Id);
//o.Treatment_Discount__c= Discount;
o.Estimated_cost__c =QuoteCount ;
SalesQuoteToUpdate.add(o);
}
update SalesQuoteToUpdate;
}
Catch(Exception e)
{
//ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.FATAL, 'Please check treatment object');
//ApexPages.addMessage(myMsg);
for(Treatments__c t :trigger.new)
{
//t.addError('Please check treatment object');
}
}
}
//When deleting created quote
if(trigger.isDelete)
{
for(Treatments__c p : trigger.old)
{
SQIds.add(p.Sales_Quote_Id__c);
system.debug('Quote id'+SQIds);
PFamily.add(p.Name);
}
//Map will contain one appointment Id to one Count value(no of Invoice)
map<Id,Decimal> SalesQuoteMap = new map<Id,Decimal>();
map<Id,Decimal> SalesQuoteMap1 = new map<Id,Decimal>();
List<Treatments__c > PF=[select id,Name,Sales_Quote_Id__c from Treatments__c where Sales_Quote_Id__c IN :SQIds AND Name=:PFamily];
//use group by to have a single Quote Id with a single sum value
if(PF.size()>0)
{
for(AggregateResult q : [select Sales_Quote_Id__c,SUM(Total_Price__c) from Treatments__c where Name=:PFamily AND Sales_Quote_Id__c IN :SQIds group by Sales_Quote_Id__c])
{
SalesQuoteMap.put((Id)q.get('Sales_Quote_Id__c'),(Double)q.get('expr0'));
}
/*for(AggregateResult q : [select Sales_Quote_Id__c,SUM(Credit_Adjustments__c) from Treatments__c where Name=:PFamily AND Sales_Quote_Id__c IN :SQIds group by Sales_Quote_Id__c])
{
SalesQuoteMap1.put((Id)q.get('Sales_Quote_Id__c'),(Double)q.get('expr0'));
}*/
List<gii__SalesQuote__c> SalesQuoteToUpdate = new List<gii__SalesQuote__c>();
//Run the for loop on sales quote using the non-duplicate set of Quote Ids
for(gii__SalesQuote__c o : [Select Id, Treatment_Discount__c,Estimated_cost__c from gii__SalesQuote__c where Id IN :SQIds])
{
Double QuoteCount = SalesQuoteMap.get(o.Id);
//Double Discount = SalesQuoteMap1.get(o.Id);
//o.Treatment_Discount__c= o.Treatment_Discount__c-Discount;
o.Estimated_cost__c =o.Estimated_cost__c-QuoteCount;
SalesQuoteToUpdate.add(o);
}
update SalesQuoteToUpdate;
}
}
}
//Test class
@isTest
private class testRollUpNoOfTeatmentQuote
{
static testMethod void countNoOftreatmentQuote()
{
Datetime myDate = datetime.newInstance(2008, 2, 5, 8, 30, 12);
Profile pf = [Select Id from Profile where Name='System Administrator'];
User u = new User();
u.FirstName='Test';
u.LastName='User';
u.Email='shiv@test.com';
u.CompanyName='KVP';
u.Title='Software Engineer';
u.Username='shiv@kvpcorp.com';
u.Alias='test';
u.communityNickName='kvpian';
u.TimeZoneSidKey='America/Mexico_City';
u.LocaleSidKey='en_US';
u.EmailEncodingKey='ISO-8859-1';
u.ProfileId=pf.Id;
u.LanguageLocaleKey = 'en_US';
insert u;
//creating clinic record
Clinic__c cl = new Clinic__c(Name = 'Ajax');
insert cl;
//creating clinic record
Referral_Card__c r = new Referral_Card__c(Name = 'XXX123',Referral_Card_Type__c='rty');
insert r;
//creating staff record
Staff__c staff = new Staff__c(Name = u.id,User_Name__c=u.id);
insert staff;
//creating rsource record
Resource__c resource = new Resource__c(Name = 'X-rayMachine',Clinic__c=cl.Id);
insert resource;
//creating staff schedule record
Staff_Schedule__c staffSchedule = new Staff_Schedule__c(Staff__c=staff.id, Shift_Start__c=myDate,Shift_Endds__c=myDate.addDays(1), Clinic__c=cl.id);
insert staffSchedule;
//creating resource schedule
Resource_Schedule__c resourceSchedule = new Resource_Schedule__c(Close_Time__c=myDate.addDays(1), Open_Time__c=myDate, Clinic__c=cl.id,Staff_Name__c=staff.id, Name__c = resource.id);
insert resourceSchedule;
//Creating record for patient
contact p= new contact(FirstName='Michel',No_of_Appointment__c=1,No_Of_Webcam_Used__c=1, LastName='Methew',Email='Michel@gmail.com', Status__c='open', Preferred_Phone_Number__c='12345678', LeadSource='ccr');
insert p;
//creating record for treatment
Treatments1__c t= new Treatments1__c(Name='SkinTightning', Resource_Name__c= resource.id,Type__c='Treatment',Price__c=100);
insert t;
//Creatting appointment record
opportunity o=new opportunity(Clinic__c=cl.Id,Treatment_Name__c = t.Id, Name='testAppointMent', CloseDate=system.Today(), Appointment_Start_Date_Time__c=myDate,Appointment_End_Date_Time1__c=myDate.addDays(1),StageName='booked', Resource__c=resource.id, Patient_Name__c=p.id);
insert o;
//Createing record for Campaign
Campaign c= new Campaign(Name='XYZ');
insert c;
//Createing record for Account
Account a= new Account(Name='Skin Vitality');
insert a;
//Creating treatment pitch record
Treatment_Pitch__c tp=new Treatment_Pitch__c(Name='maintenance',Treatments__c=t.id,Treatment_Number__c=1);
Insert tp;
//Create sales Quote
gii__SalesQuote__c SQ = new gii__SalesQuote__c(
Customer_Name__c=p.Id,
Appointment_Name__c=o.Id,
Medical_Representative__c=staff.Id,
Estimated_cost__c=50,
Status__c='Invoiced',
gii__Account__c=a.id
);
insert SQ;
//Create invoice
if(SQ.Status__c=='Invoiced')
{
Invoices__c Inv = new Invoices__c (
Sales_Quote_Id__c=SQ.Id,
Contact_ID__c=p.Id,
Appointment_Name__c=o.Id
);
insert Inv;
}
//Create treatment
if(SQ.Status__c=='Invoiced' && t.Type__c=='Treatment')
{
Treatments__c Trt= new Treatments__c(
Treatment_Name__c=t.Id,
of_Treatment__c=2,
Sales_Quote_Id__c=SQ.Id
);
insert Trt;
}
//Update sales quote
gii__SalesQuote__c SQ1 = [select Estimated_cost__c from gii__SalesQuote__c limit 1];
List<gii__SalesQuote__c> QuoteListToUpdate =new List<gii__SalesQuote__c>();
for(integer i=0 ; i<250 ;i++)
{
SQ1.Estimated_cost__c = 200;
QuoteListToUpdate.add(SQ1);
Update QuoteListToUpdate ;
}
//delete TreatmentListToInsert[0];
}
}
Please help me to solve this problem.
Regards,
DD
Hi Visitor,
I have the same problem.
Is that running in your sanbox from which you happened to do a refresh recently?
What about your production, running fine i suppose?
Will post when i get more info on resolution
Hi Visitor,
If found the problem on my end. Please check the following:
If you are experiencing this in a Developper Sandbox, that simply means that your OM Glovia license has not been installed in that particular sandbox, just proceed to their installation manual for that particular sandbox.
In my case, the problem was that my testclass metadata api version was not matching the environment api version. (ex: i had v25.0 but the Glovia sandbox api target was 20.0). By simply changing the version to match in the metadata.xml fixed it.
Hope this helps you too.
Rgds,
Try following to create system policy record
gii__SystemPolicy__c s;
//check if system policy record already exists
for(gii__SystemPolicy__c sys : [select id,
gii__StockUM__c
from gii__SystemPolicy__c where name = 'GII' LIMIT 1]){
s = sys;
}
if (s == null) {
gii__SystemPolicy__c s = new gii__SystemPolicy__c (name = 'GII',
gii__StockUM__c = 'Each',
gii__PriceBookName__c = 'Standard',
gii__Warehouse__c = wh.id);
insert s;
}
Thanks pp11222 !
Works like a charm.
I did add some gii__Warehouse__c creation code to make the wh.id reference work but it is working like a charm now !
Thanks,