• Test class
  • NEWBIE
  • 0 Points
  • Member since 2012

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 0
    Replies

how to change lead conversion page layout in salseforce ?

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

trigger PitchProductPrice on Pitch_Product__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(Pitch_Product__c p : trigger.new)
    {
      SQIds.add(p.Sales_Quote__c);
      PTIDs.add(p.Product__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>();
  List<Pitch_Product__c> PF=[select id,Product__c ,Product_Family__c from Pitch_Product__c where Sales_Quote__c  IN :SQIds AND Product__c IN :PTIDs ];
  //use group by to have a single appointment Id with a single sum value
  for(AggregateResult q : [select Sales_Quote__c,SUM(Total_price__c) from Pitch_Product__c where Sales_Quote__c IN :SQIds group by Sales_Quote__c])
    {
      SalesQuoteMap.put((Id)q.get('Sales_Quote__c'),(Double)q.get('expr0'));      
    }
   /* for(AggregateResult q : [select Sales_Quote__c,SUM(Discount__c) from Pitch_Product__c where Sales_Quote__c IN :SQIds group by Sales_Quote__c])
    {      
      SalesQuoteMap1.put((Id)q.get('Sales_Quote__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,Credit_Adjustments__c, Product_Cost__c from gii__SalesQuote__c where Id IN :SQIds])  
   {
      Double QuoteCount = SalesQuoteMap.get(o.Id); 
      //Double Discount =  SalesQuoteMap1.get(o.Id); 
      //o.Credit_Adjustments__c= Discount;  
      o.Product_Cost__c=QuoteCount ;      
      SalesQuoteToUpdate.add(o);
   }
   update SalesQuoteToUpdate;
 }
 
//When deleting created quote
if(trigger.isDelete)
{
    for(Pitch_Product__c p : trigger.old)
    {
      SQIds.add(p.Sales_Quote__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<Pitch_Product__c> PF=[select id,Name,Sales_Quote__c ,Product_Family__c from Pitch_Product__c where Sales_Quote__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__c,SUM(Total_price__c),SUM(Discount__c) from Pitch_Product__c where Name=:PFamily AND Sales_Quote__c IN :SQIds group by Sales_Quote__c])
    {
      SalesQuoteMap.put((Id)q.get('Sales_Quote__c'),(Double)q.get('expr0'));
    }
    /*for(AggregateResult q : [select Sales_Quote__c,SUM(Discount__c) from Pitch_Product__c where Name=:PFamily AND Sales_Quote__c IN :SQIds group by Sales_Quote__c])
    {      
      SalesQuoteMap1.put((Id)q.get('Sales_Quote__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, Credit_Adjustments__c,Product_Cost__c from gii__SalesQuote__c where Id IN :SQIds])  
   {
      Double QuoteCount = SalesQuoteMap.get(o.Id);
      //Double Discount =  SalesQuoteMap1.get(o.Id); 
      //o.Credit_Adjustments__c= o.Credit_Adjustments__c-Discount;
      o.Product_Cost__c=o.Product_Cost__c- QuoteCount;
      SalesQuoteToUpdate.add(o);
           
   }
   update SalesQuoteToUpdate;
  }
}
}

 

 

Please help me to write test class for this trigger.

 

Thank you.