• Eli Flores
  • NEWBIE
  • 40 Points
  • Member since 2014

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 4
    Replies
I am trying to create an APEX trigger that will classify an account as Major, Mid , Inside, and Inside small. Here is the break out of filters that Major and Mid have. 

Major = Accounts with Employee Count >= 10,000
Accounts with Annual Revenue >=500,000,000
Accounts where F500 is checked
Accounts Where F501- 1000 is checked and Employee Count is >=10,000 and Annual Revenue >= 500,000,000
Accounts where industry  =  Pharma/Biotech, Energy or Fed - Gov

Mid = Accounts with Employee Count 4000<=9999
Accounts with Annual Revenue 250,000,000 >= 499,999,999
Accounts Where F501- 1000 is checked 
Accounts where industry  =  Education and Employees >= 8,000

Inside = Accounts with Employee Count  3999<=1500

Inside Small  = Accounts with Employee Count <1499

I have 4 checkboxs that will classify the type and allow me to write workflow rules to assign correctly. Below is the start of my trigger but I feel like I am doing it wrong and would love to see what you guys think?

trigger AssignTerritoryType on Account (before insert, before update) {
For (Account a :trigger.new){
  if (a.NumberOfEmployees >= 10000){
   (a.major__c = True);
  }
  else if (a.AnnualRevenue >= 500000000){
   (a.major__c = True);
  }
  else if (a.Fortune_500__c = true){
   (a.major__c = True);
  }
  else if (a.Fortune_500_1000__c = True){
   if (a.NumberOfEmployees >=10000){
    if(a.AnnualRevenue >= 500000000){
     (a.major__c =true);
    }
   }
  }
  else if (a.Industry = 'Pharma/BioTech'){
   (a.major__c = True);
  }
  else if (a.Industry = 'Energy'){
   (a.major__c = True);
  }
  else if (a.Industry = 'Fed - Gov'){
   (a.major__c = True);
  }
}

}
I am trying to create an APEX trigger that will classify an account as Major, Mid , Inside, and Inside small. Here is the break out of filters that Major and Mid have. 

Major = Accounts with Employee Count >= 10,000
Accounts with Annual Revenue >=500,000,000
Accounts where F500 is checked
Accounts Where F501- 1000 is checked and Employee Count is >=10,000 and Annual Revenue >= 500,000,000
Accounts where industry  =  Pharma/Biotech, Energy or Fed - Gov

Mid = Accounts with Employee Count 4000<=9999
Accounts with Annual Revenue 250,000,000 >= 499,999,999
Accounts Where F501- 1000 is checked 
Accounts where industry  =  Education and Employees >= 8,000

Inside = Accounts with Employee Count  3999<=1500

Inside Small  = Accounts with Employee Count <1499

I have 4 checkboxs that will classify the type and allow me to write workflow rules to assign correctly. Below is the start of my trigger but I feel like I am doing it wrong and would love to see what you guys think?

trigger AssignTerritoryType on Account (before insert, before update) {
For (Account a :trigger.new){
  if (a.NumberOfEmployees >= 10000){
   (a.major__c = True);
  }
  else if (a.AnnualRevenue >= 500000000){
   (a.major__c = True);
  }
  else if (a.Fortune_500__c = true){
   (a.major__c = True);
  }
  else if (a.Fortune_500_1000__c = True){
   if (a.NumberOfEmployees >=10000){
    if(a.AnnualRevenue >= 500000000){
     (a.major__c =true);
    }
   }
  }
  else if (a.Industry = 'Pharma/BioTech'){
   (a.major__c = True);
  }
  else if (a.Industry = 'Energy'){
   (a.major__c = True);
  }
  else if (a.Industry = 'Fed - Gov'){
   (a.major__c = True);
  }
}

}
Public Class ContractFunctionsCloneContractAndOLIs
{

Public static void CloneMaintContractAndLineItems(Map<Id,Contract> oldMap, Map<Id,Contract> newMap)
      {
        List<Id> ContractToClone = new List<Id>();
        List<Id> ContractLineItemsToClone = new List<Id>();
       
        Date StartDate;
        Date EndDate;


       
      
        Integer NumberOfDays = 0;
        Integer NumberOfMonths = 0;
        Integer NumberOfYears = 0;
        Double YearTerm = 0;
        Integer NumberOfLeapYearDays = 0;
        Integer TermsByMonth = 0;
        Integer Prevcount =0;
       
        Boolean MaintTermMisMatch;
       
        String OriginalCase;
       
        Date CurrentDay;
        Date PrevCurrentDay;      

        Integer PrevNumberOfDays =0;
        Date PrevStartDate;
        Date PrevEndDate;
       
        Integer PrevNumberOfLeapYearDays =0;      
      
             
        for(Contract c : newMap.Values())
        {
            ContractToClone.add(c.Id);
      
        }

        
        for(Contract_Line_Item__c CLI :[Select id from Contract_Line_Item__c where Contract__c in :ContractToClone])
        {
            ContractLineItemsToClone.add(CLI.id);
        }
      
       Contract newContract = new Contract();
       
        if(ContractToClone.size() > 0 && ContractLineItemsToClone.size() > 0)
        {
            for(Contract c : [Select id, Status, Attn_To__c, Original_Case__c, Maintenance_out_of_sync__c, NewlyCreatedNumDays__c, DateFinal__c,PrevNumberOfDays__c, PrevStartDate__c, PrevEndDate__c, PrevNumberOfLeapYearDays__c, Term_In_Days__c, XNumberOfDays__c, AccountId, XNumberOfLeapYearDays__c, NumberOfLeapYearDays2__c, SpecialTerms, FEndDate__c, FCompareDayEndDate__c, Total_Maintenance_Price__c,Months_between_start_and_end__c,Override_Total_Price__c,StartDate, Contract_End_Date__c, Case__c, RecordTypeId from Contract where Id in :ContractToClone ])
            {

List<Contract> ContractsToInsert = new List<Contract>();
     

      
                newContract.Total_Maintenance_Price__c = c.Total_Maintenance_Price__c;
                newContract.Status = 'Pending';
                newContract.AccountId = c.AccountId;
                newContract.StartDate = c.Contract_End_Date__c + 1;
                newContract.RecordTypeId = ServiceClass.getRecordTypesNameMap('Contract').get('Maintenance Contract').Id;
                newContract.Parent_Contract__c = c.id;
               
                                            
                ContractsToInsert.add(newContract);
        insert(ContractsToInsert);  
       
         List<Contract_Line_Item__c> ContractLineItemsToInsert = new List<Contract_Line_Item__c>();
               
                String ContractId;
                String AccountId;
                String CaseId;
                String CLIStatus;
                           
            for(Contract insertedContracts : [Select Id, Case__c, AccountId from Contract where id in :ContractsToInsert])
            {
                ContractId = insertedContracts.id;
                AccountId = insertedContracts.AccountId;
                CaseId = insertedContracts.Case__c;
                CLIStatus = 'Pending';
               
               
               
                            }
            for(Contract_Line_Item__c cc : [Select id, Maintenance_Sales_Price__c, Contract_Line_Item_Status__c, Product_LU__c, Quantity__c, List_Price__c from Contract_Line_Item__c where Id in :ContractLineItemsToClone])
                {
                    Contract_Line_Item__c newCLI = new Contract_Line_Item__c();
                   
                   
                    newCLI.Contract_Line_Item_Status__c = CLIStatus;
                    newCLI.Contract__c = ContractId;
                    //newCLI.Case_Id__c = CaseId;
                    newCLI.Account__c = AccountId;
                    newCLI.Contract_Line_Item_Origin__c = 'Contract Clone Follow Up Contract';
                    newCLI.Product_LU__c = cc.Product_LU__c;
                    newCLI.Quantity__c = cc.Quantity__c;
                    newCLI.List_Price__c = cc.List_Price__c;    
                    newCLI.Maintenance_Sales_Price__c = cc.Maintenance_Sales_Price__c;
                    if(cc.Contract_Line_Item_Status__c == 'Do Not Renew')
                    {
                         newCLI.Contract_Line_Item_Status__c = 'Do Not Renew';
                    }        
                    if(cc.Contract_Line_Item_Status__c == 'Cancelled')
                    {
                         newCLI.Contract_Line_Item_Status__c = 'Cancelled';
                    }        
                    ContractLineItemsToInsert.add(newCLI);
                }
                insert(ContractLineItemsToInsert);
                update(ContractLineItemsToInsert);  
            }
       
       
          

      }}}