• karan p
  • NEWBIE
  • 5 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 0
    Replies
Hello all

I have "contaminats" Object as a related list for Cases and the field in the objects were as follows (Name, Feed(CheckBox), Regeneration medium(CheckBox)). i need to Auto create 6 contaminats (oxygen,CO,H2,Olefins,Sulfur  components,Chloride components) upon case creation as unchecked
Can any one help me with a class to create these contaminats .
hello all

Below is my apex class could you please help me out to correct my test class to improve my code coverage 

public class callmeetings
{
    public Map<Id, Call_Meeting__c> cmMap {get; set;}
    public String selectedcm{get; set;}
    public String tuId;
    
    public callmeetings()
    {
        tuId = ApexPages.currentPage().getParameters().get('tId');        
        cmMap = new Map<Id, Call_Meeting__c>([Select Id, Name, User__c, User__r.Name, Treating_Unit__c from Call_Meeting__c WHERE Treating_Unit__c = null]);
    }
    
    
    public PageReference selectThis() {
        
        if(cmMap.containsKey(selectedcm))
        {
            Call_Meeting__c tempMeeting = cmMap.get(selectedcm);
            tempMeeting.Treating_Unit__c = tuId;
            update tempMeeting;
            return (new PageReference('/'+tuId));
        }
        else
        {
            return null;
        }
    }        
}

Test class 

@isTest
private class callmeetingsTest
{
    static testMethod void updateCallmeeting()
    {
        id uopAccountId;
        Schema.DescribeSObjectResult d1 = Schema.SObjectType.Account;
        Map<String,Schema.RecordTypeInfo> rtMap1 = d1.getRecordTypeInfosByName();
        Schema.RecordTypeInfo uoprt =rtMap1.get('UOP Accounts');
        uopAccountId=uoprt.getRecordTypeId(); 
       
        ContactRecordType__c rectype = new ContactRecordType__c();
        rectype.Name='UOP_AccountRecordType';
        rectype.UOP_Account_RecordType__c=uopAccountId;
        insert rectype;
        
        Profile p=[select id from Profile where Name='UOP - Business'];
        UOP_Profiles__c up=new UOP_Profiles__c();
        up.Name='UOP Profile ID List';
        up.UOP_Business__c=p.id;
        insert up;
        
        sales_district__c sd=new sales_district__c();
        sd.Name='INDIA';
        insert sd;
        system.debug('*******sales district********'+sd);
        
        Uop_geo_region__c ur=new Uop_geo_region__c ();
        ur.Name='INDIAN SUBCONTINENT';
        insert ur;
        system.debug('*******Uop_geo_region__c********'+ur); 
        
        SAP_Customer_Info__c testcustomer = new SAP_Customer_Info__c();       
        testcustomer.Name='100462';
        testcustomer.UOP_Company_Name__c='AGIPPETROIL SPA';
        testcustomer.UOP_Geographic_Region__c='EUR';
        testcustomer.UOP_Sales_District__c=sd.id;
        testcustomer.UOP_Geo_Region__c=ur.id;
        testcustomer.UOP_Address1__c='DEVKARAN MANSION IIND FLR';
        testcustomer.UOP_Address2__c='79 PRINCESS STREET';
        testcustomer.UOP_City__c='Hyderabad';
        testcustomer.UOP_Honeywell_Geo_Region__c='India';
        testcustomer.UOP_Country__c='INDIA';
        insert testcustomer; 
        system.debug('*******testcustomer********'+testcustomer);     
        
         
        Country__c c=new Country__c();
        c.Name='INDIA';
        c.Region__c='India';
        insert c;
        
        Account acc=new Account();
        acc.Name='Test Name';
        //acc.UOP_Delta_Type__c='Agent';
        acc.RecordTypeId=uopAccountId;
        acc.Sales_District__c=sd.id; 
        acc.SAP_Customer_Info__c=testcustomer.id;                
        acc.BillingStreet ='sfdc';
        acc.BillingState ='sfdc';
        acc.BillingCountry ='INDIA';
        acc.BillingPostalCode='12221';
        insert acc;
        system.debug('Account.country'+acc.BillingCountry);

        acc= [Select OwnerID, Owner.ID From Account where ID = :acc.id];
        system.assertNOTEquals(null,acc.OwnerID);
        system.assertNOTEquals(null,acc.Owner.ID);
        
        Treating_Units__c TU = New Treating_Units__c ();
        TU.Account__c=acc.ID;
        TU.Unit_Reference_number__c='D-206';
        TU.Contaminants_Removed__c='H2O';
        TU.Carrier_Stream__c='Natural GAS';
        insert TU;
        
        Call_Meeting__c CM = New Call_Meeting__c ();
        CM.Company__c= acc.ID;
        CM.Due_Date__c = Datetime.newInstance(2016, 8, 16);
        CM.Meeting_Location__c='Teleconference';
        insert CM; 
    }
}
Hello as i am new to test classes Could  any one let me know how to write a test class for my utility class that is declared in my trigger.
. the purpose of the below code is we wanted to clone an opportunity with related old opportunity related class

public class treatingDatabaseTrigger_UtilityClass  
{
    public static void treatingDatabase(List<opportunity> newRecord)
    {
        Set<Id> recordTypeIds = new Set<Id>();
        Set<Id> oldOppIds = new Set<Id>();
        recordTypeIds.add(Schema.SObjectType.Opportunity.getRecordTypeInfosByName().get('Child Opportunity').getRecordTypeId());
        recordTypeIds.add(Schema.SObjectType.Opportunity.getRecordTypeInfosByName().get('CA&S Opportunity').getRecordTypeId());
        List<treating__c> insertList = new List<treating__c>();
        for(Opportunity opp : newRecord)
        {
            if((opp.ID__c != null) && (recordTypeIds.contains(opp.RecordTypeId)))
            {
                 oldOppIds.add(opp.ID__c);
            }
        }
        if(!oldOppIds.isEmpty())
        {
            Map<Id, Opportunity> oldOppMap = new Map<Id, Opportunity>([Select Id, (Select Id, Opportunity__c, Treating_Unit__c from Treating_Databases__r) from Opportunity WHERE Id IN :oldOppIds]);
            for(Opportunity opp : newRecord)
            {
                if(oldOppMap.containsKey(opp.ID__c))
                {
                    for(treating__c eachtreating : oldOppMap.get(opp.ID__c).Treating_Databases__r)
                    {
                        treating__c newtreating = new treating__c();
                        newtreating.Treating_Unit__c = eachtreating.Treating_Unit__c;
                        newtreating.Opportunity__c = opp.Id;
                        insertList.add(newtreating);    
                    }
                }
            }
        }
        if(!insertList.isEmpty())
        {
            insert insertList;
        }
    
    }
}
public class LeadRLinAccountController
{  
  public Account acc;
  public List<lead> leadRec {get; set;}
  public List<Lead> shortViewLst {get; set;}
  public boolean shortview {get; set;}
  
  public LeadRLinAccountController(ApexPages.standardController stdCon)
  {    
    this.acc=(Account)stdCon.getRecord();
    shortview = TRUE;
    leadRec=[select id,convertedAccountId,Lead_name_link__c, createdDate,email, Company, LeadSource, Status,ConvertedDate FROM Lead where convertedAccountId=:acc.id  and  isConverted=true];
    shortViewLst = new List<Lead>();
    if(!leadRec.isEmpty())
        for(integer i=0; i<leadRec.size(); i++)
         if(i<=5)
            shortViewLst.add(leadRec[i]);    
  }
  
  public PageReference relatedRecords()
  { 
    shortview = FALSE;
    return null;
  }
  
 
}