• Travis Wright
  • NEWBIE
  • 85 Points
  • Member since 2014
  • Sr Application Manager
  • The Network Inc

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 12
    Questions
  • 21
    Replies
Not sure why I am getting this looking at the SOQL statement I have the name in the Query, Here is the full error. 

Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, ProjectrollupOLi: execution of AfterUpdate caused by: System.SObjectException: SObject row was retrieved via SOQL without querying the requested field: Opportunity.Communications_Team__c Trigger.ProjectrollupOLi: line 65, column 1: []
Error is in expression '{!doSaveOLI}' in component <apex:commandButton> in page productsearch: Class.ProductSearch.doSaveOLI: line 1016, column 1

Here is the Trigger,

trigger ProjectrollupOLi on OpportunityLineItem (after insert, after update, before delete)

    Set <String> oppIdSet = new Set <String>();

    if(Trigger.isAfter)
        for(OpportunityLineItem oli : Trigger.new)
            oppIdSet.add(oli.OpportunityId);
    if(Trigger.isBefore)
        for(OpportunityLineItem oli : Trigger.old)
            oppIdSet.add(oli.OpportunityId);
    
    Map<Id,Opportunity> oppOldMap = new Map<Id,Opportunity>([Select Id, Implementation_Team__c, Training_Team__c From Opportunity Where Id IN :oppIdSet]);

    Set<String> oppImplementationTeamList = new Set<String>();
    Set<String> oppTrainingTeamList = new Set<String>();
    Set<String> oppCommunicationTeamList = new Set<String>();
        
    List <OpportunityLineItem> oliList = [Select UnitPrice, Quantity, PricebookEntry.Product2Id, TotalPrice,PricebookEntry.Product2.Name, Description,
        Converted_to_Asset__c,Asset__c,PricebookEntry.Product2.Create_Asset__c, PricebookEntry.Product2.Sales_Order_Group__c, OpportunityId From OpportunityLineItem where 
        OpportunityId IN : oppIdSet And (PricebookEntry.Product2.Product_Reporting_Category__c = 'Services' or PricebookEntry.Product2.Name LIKE '%Communications%')];

    for(OpportunityLineItem oli : oliList)
    {
        if(oli.PricebookEntry.Product2.Sales_Order_Group__c == 'Hotline Services' || oli.PricebookEntry.Product2.Sales_Order_Group__c == 'Policy Management Services' || oli.PricebookEntry.Product2.Sales_Order_Group__c == 'Incident Management Services')
        {
            oppImplementationTeamList.add(oli.OpportunityId);
        }
        if(oli.PricebookEntry.Product2.Sales_Order_Group__c == 'ReadyTraining Services')
        {
            oppTrainingTeamList.add(oli.OpportunityId);
        }
        if(oli.pricebookEntry.Product2.Name.Contains('Communications'))
        {
            oppCommunicationTeamList.add(oli.OpportunityId);
        }
    }
    
    Map<Id,Opportunity> updateMap = new Map<Id,Opportunity>();
    
    for(Id oppId : oppIdSet)
    {
        Opportunity opp = new Opportunity(Id = oppId, Implementation_Team__c = false, Training_Team__c = false, Communications_Team__c = false);
        updateMap.put(oppId, opp);
    }
    
    for(Id oppId : oppImplementationTeamList)
    {
        Opportunity opp = updateMap.get(oppId);
        opp.Implementation_Team__c = true;
    }
    
    for(Id oppId : oppTrainingTeamList)
    {
        Opportunity opp = updateMap.get(oppId);
        opp.Training_Team__c = true;
    }
    for(Id oppId : oppCommunicationTeamList)
        {
            Opportunity opp = updateMap.get(oppId);
            opp.Communications_Team__c = true;
        }
    for(Opportunity oppOld : oppOldMap.values())
    {
        Opportunity oppNew = updateMap.get(oppOld.Id);
        if(oppNew.Implementation_Team__c == oppOld.Implementation_Team__c && oppNew.Training_Team__c == oppOld.Training_Team__c && oppNew.Communications_Team__c == oppOld.Communications_Team__c)
            updateMap.remove(oppOld.Id);
    }
    
    List<Opportunity> updateList = updateMap.values();
    
    if(updateList.size()>0)
        update updateList;
}
Hey Guys need another set of eyes on this as I am not sure why this is happening. 

trigger Projectrollup on OpportunityLineItem (after insert, after update, before delete)

    Set oppIdSet = new Set();

    if(Trigger.isAfter)
        for(OpportunityLineItem oli : Trigger.new)
            oppIdSet.add(oli.OpportunityId);
    if(Trigger.isBefore)
        for(OpportunityLineItem oli : Trigger.old)
            oppIdSet.add(oli.OpportunityId);
    
    Map oppOldMap = new Map([Select Id, Implementation_Team__c, Training_Team__c From Opportunity Where Id IN :oppIdSet]);

    Set oppImplementationTeamList = new Set();
    Set oppTrainingTeamList = new Set();
        
    List oliList = [Select UnitPrice, Quantity, PricebookEntry.Product2Id, TotalPrice,PricebookEntry.Product2.Name, Description,
        Converted_to_Asset__c,Asset__c,PricebookEntry.Product2.Create_Asset__c, PricebookEntry.Product2.Sales_Order_Group__c, OpportunityId From OpportunityLineItem where 
        OpportunityId IN : oppIdSet And (PricebookEntry.Product2.Product_Reporting_Category__c = 'Services' or PricebookEntry.Product2.Name LIKE '%Communications%')];

    for(OpportunityLineItem oli : oliList)
    {
        if(oli.PricebookEntry.Product2.Sales_Order_Group__c == 'Hotline Services' || oli.PricebookEntry.Product2.Sales_Order_Group__c == 'Policy Management Services' || oli.PricebookEntry.Product2.Sales_Order_Group__c == 'Incident Management Services')
        {
            oppImplementationTeamList.add(oli.OpportunityId);
        }
        if(oli.PricebookEntry.Product2.Sales_Order_Group__c == 'ReadyTraining Services')
        {
            oppTrainingTeamList.add(oli.OpportunityId);
        }
    }
    
    Map updateMap = new Map();
    
    for(Id oppId : oppIdSet)
    {
        Opportunity opp = new Opportunity(Id = oppId, Implementation_Team__c = false, Training_Team__c = false);
        updateMap.put(oppId, opp);
    }
    
    for(Id oppId : oppImplementationTeamList)
    {
        Opportunity opp = updateMap.get(oppId);
        opp.Implementation_Team__c = true;
    }
    
    for(Id oppId : oppTrainingTeamList)
    {
        Opportunity opp = updateMap.get(oppId);
        opp.Training_Team__c = true;
    }
    
    for(Opportunity oppOld : oppOldMap.values())
    {
        Opportunity oppNew = updateMap.get(oppOld.Id);
        if(oppNew.Implementation_Team__c == oppOld.Implementation_Team__c && oppNew.Training_Team__c == oppOld.Training_Team__c)
            updateMap.remove(oppOld.Id);
    }
    
    List updateList = updateMap.values();
    
    if(updateList.size()>0)
        update updateList;
}
I am not sure how to fix this, Any help would be great. 

trigger Projectrollup on Opportunity (after insert, after update)
{
  Map<Id,Opportunity> oppIds = new Map<Id,Opportunity>();
  List<Opportunity> updateList = new List<Opportunity>();
 
  for(Opportunity o : Trigger.new)
  {
      oppIds.put(o.id,o);
                                        
  }
 
  OpportunityLineItem[] OLI = [Select UnitPrice, Quantity, PricebookEntry.Product2Id, TotalPrice,PricebookEntry.Product2.Name, Description,
                                Converted_to_Asset__c,Asset__c,PricebookEntry.Product2.Create_Asset__c, PricebookEntry.Product2.Sales_Order_Group__c
                               From OpportunityLineItem
                               where OpportunityId IN : oppIds.keySet()
                               And (PricebookEntry.Product2.Product_Reporting_Category__c = 'Services'
                               or PricebookEntry.Product2.Name LIKE '%Communications%')];
 
  for(OpportunityLineItem o : OLI)
  {
    if(o.PricebookEntry.Product2.Sales_Order_Group__c == 'Hotline Services' || o.PricebookEntry.Product2.Sales_Order_Group__c == 'Policy Management Services' || o.PricebookEntry.Product2.Sales_Order_Group__c == 'Incident Management Services')
    {
      Opportunity opp = new Opportunity(id= o.OpportunityId);
      opp.Implementation_Team__c = true;
      updateList.add(opp);
    }
    if(o.PricebookEntry.Product2.Sales_Order_Group__c == 'ReadyTraining Services')
    {
      Opportunity opp = new Opportunity(id=o.OpportunityId);
      opp.Training_Team__c = true;
      updateList.add(opp);
    }
   }
 
  if(updateList.size()>0)
  {
    update updateList;
  }
}
 
I need to update some custom fields on the opportunity when certin products are selected. I just need the starting point to update the opportunity I believe that everything else is correct. 

If Pricebook2.Product2.Sales_Order_Group__c = 'Hotline Services' OR 'Policy Management Services' OR 'Incident Management Services' I need to update Implementation_Team__c to True 
Else if Pricebook2.Product2.Sales_Order_Group__c = 'ReadyTraining Services' I need to Update Training_Team__c to True

There are a couple more values but I am sure that I can figure that part out with a sample. Also I don't think the ELSE IF is right becuase it should be possible that both are selected. 

Any help would be greatly appricated. Below is what I have started but not sure if it is all correct. 


trigger Projectrollup on Opportunity (after insert, after update) {
    Map<PricebookEntry.Product2.Name,OpportunityLineItem> prod = new map<PricebookEntry.Product2.Name,OpportunityLineItem>();
        for(Opportunity o: trigger.new){
            if(o.HasOpportunityLineItem == true){
                string opptyId = o.id;
                OpportunityLineItem[] OLI = [Select UnitPrice, Quantity, PricebookEntry.Product2Id, 
                                             TotalPrice,
                                             PricebookEntry.Product2.Name, Description, Converted_to_Asset__c,Asset__c,
                                             PricebookEntry.Product2.Create_Asset__c, PricebookEntry.Product2.Sales_Order_Group__c
                                      From OpportunityLineItem 
                                      where OpportunityId = :opptyId
                                      And   PricebookEntry.Product2.Product_Reporting_Category__c = 'Services'];
 
The following trigger is not eveluating past the Prospect Major for some reason. If I comment out the major assignment I get Mid for an account that should be Inside. I am hoping I am missing something small as I need to reassign accounts this evening after 5pm EST. I am sure there is a better way to do it so I am sorry for all the over code. 

trigger AssignTerritoryType on Account (Before insert, Before update) {
    For (Account a :trigger.new){
    IF((a.Current_Account_Status__c == 'Customer' || 
        a.Current_Account_Status__c == 'Customer - In Play') && 
            a.NumberOfEmployees >= 10000 )
            { a.Major__c=true;
              a.Mid__c=False;
              a.Inside__c=False;
              }
    else IF((a.Current_Account_Status__c == 'Customer' || 
             a.Current_Account_Status__c == 'Customer - In Play') && 
                 (a.NumberOfEmployees > 2000 && 
                  a.NumberOfEmployees <= 10000))
            { a.Major__c=False;
              a.Mid__c=True;
              a.Inside__c=False;
             }          
    else IF((a.Current_Account_Status__c == 'Customer' || 
             a.Current_Account_Status__c == 'Customer - In Play') && 
                (a.NumberOfEmployees > 0 && 
                 a.NumberOfEmployees <= 2000))
            {a.Major__c=False;
             a.Mid__c=False;
             a.Inside__c=True;
            }         
    else if((a.Current_Account_Status__c == 'Prospect' || 
             a.Current_Account_Status__c == 'Prospect - In Play' &&
                 (a.Fortune_1000_Rank__c==NULL) &&
                 (a.NumberOfEmployees >= 9000) && 
                 (a.Industry != 'Education')==True)  ||
                    (a.Current_Account_Status__c == 'Prospect' || 
                     a.Current_Account_Status__c == 'Prospect - In Play' &&
                    (a.Fortune_1000_Rank__c==Null) && 
                     (a.AnnualRevenue >= 1000000000) && 
                     (a.Industry != 'Education')==True)  ||
                          (a.Current_Account_Status__c == 'Prospect' || 
                           a.Current_Account_Status__c == 'Prospect - In Play' &&
                           a.Industry == 'Pharma/BioTech') ||
                                (a.Current_Account_Status__c == 'Prospect' || 
                                 a.Current_Account_Status__c == 'Prospect - In Play' &&
                                 a.Industry == 'Fed - Gov')  ||
                                    (a.Current_Account_Status__c == 'Prospect' || 
                                     a.Current_Account_Status__c == 'Prospect - In Play' &&
                                     a.Fortune_1000_Rank__c <=750 ))
            {
              a.Major__c=true;
              a.Mid__c=False;
              a.Inside__c=False;
              }

    else if ((a.Current_Account_Status__c == 'Prospect' || 
              a.Current_Account_Status__c == 'Prospect - In Play' &&
             (a.NumberOfEmployees < 9000) && 
             (a.NumberOfEmployees >=3000) &&
             (a.Industry != 'Education')==True ) ||
                     (a.Current_Account_Status__c == 'Prospect' || 
                      a.Current_Account_Status__c == 'Prospect - In Play' &&
                     (a.AnnualRevenue < 1000000000) && 
                     (a.AnnualRevenue >=500000000)) ||
                          (a.Current_Account_Status__c == 'Prospect' || 
                           a.Current_Account_Status__c == 'Prospect - In Play' &&
                          (a.Fortune_1000_Rank__c >=751)) ||
                             (a.Current_Account_Status__c == 'Prospect' || 
                              a.Current_Account_Status__c == 'Prospect - In Play' &&
                             (a.NumberOfEmployees >=8000) && 
                             (a.Industry == 'Education')==True) ||
                                   (a.Current_Account_Status__c == 'Prospect' || 
                                    a.Current_Account_Status__c == 'Prospect - In Play' &&
                                    a.Industry == 'State -Gov')
           )
            {a.Major__c=False;
             a.Mid__c=True;
             a.Inside__c=False;
           }

    else   
            {a.Major__c=False;
             a.Mid__c=False;
             a.Inside__c=True;
             }
       }
}
I am writing a test class for the below APEX trigger and running into something that I have never covered before and could use some help in understanding how to cover. 

trigger fillLeadSource on Opportunity (before update) {
   Set<Id> oppsToFill = new Set<Id>();
    for(Opportunity o : trigger.new){
        if(o.LeadSource == null) {
            oppsToFill.add(o.Id);
        }
    }

    // Now we'll select all possible contacts wasting only 1 query.
    if(!oppsToFill.isEmpty()){
        List<OpportunityContactRole> roles = [SELECT OpportunityId, Contact.Name, Contact.LeadSource, Contact.Lead_Source_Name__c
            FROM OpportunityContactRole
            WHERE isPrimary = true AND Contact.LeadSource != null AND OpportunityId IN :oppsToFill];

        if(!roles.isEmpty()){
            for(OpportunityContactRole ocr : roles){
                Opportunity oppToBeFilled = trigger.newMap.get(ocr.OpportunityId);
                System.debug('Changing lead source on ' + oppToBeFilled.Name + ' from ' + oppToBeFilled.LeadSource + ' to ' + ocr.Contact.LeadSource + ' (thx to ' + ocr.Contact.Name + ' being the Primary Contact).');
                oppToBeFilled.LeadSource = ocr.Contact.LeadSource;
                oppToBeFilled.Lead_Source_Name__c = orc.Contact.Lead_Source_Name__c;
            }
        }
    }
}


Lines I need help Covering 

            for(OpportunityContactRole ocr : roles){
                Opportunity oppToBeFilled = trigger.newMap.get(ocr.OpportunityId);
                System.debug('Changing lead source on ' + oppToBeFilled.Name + ' from ' + oppToBeFilled.LeadSource + ' to ' + ocr.Contact.LeadSource + ' (thx to ' + ocr.Contact.Name + ' being the Primary Contact).');
                oppToBeFilled.LeadSource = ocr.Contact.LeadSource;

TEST CLASS
@isTest
private class triggerfillLeadSource {
     
     static testMethod void fillLeadSource() {
     
        Account a = new Account();
        a.name = 'TNW (for Competitor Profile)';
        insert a;
        
        Contact c = new Contact();
        c.FirstName = 'Test';
        c.LastName = 'User 1';
        c.pi__score__c = 20;
        c.accountId = a.Id;
        c.LeadSource = 'Admin';
        insert c;
        
        c.pi__score__c = 30;
        update c;
        
        Delete c;
         
        Database.undelete(c.id);
        
        Asset ass = new Asset();
        ass.name = 'test Asset';
        ass.Price = 100;
        ass.Status = 'Purchased';
        ass.accountid = a.Id;
        insert ass;
        
        ass.price = 200;
        update ass;
        
        delete ass;
        
        Database.Undelete(ass.Id);
         
        Opportunity o = New Opportunity();
         o.Name = 'test';
         o.AccountId = a.Id;
         o.CloseDate = system.today();
         o.StageName = '0. Sales Ready';
         o.Type = 'New';
         o.LeadSource ='Admin';
         Insert o;
         
         OpportunityContactRole ocr = New OpportunityContactRole();
         ocr.opportunityId = o.Id;
         ocr.ContactId = c.Id;
         ocr.IsPrimary = True;
         insert ocr;
         
         Opportunity opp = [SELECT Leadsource,Name,ID from Opportunity where ID=:o.Id];
         System.assertEquals(c.LeadSource,opp.LeadSource);
       }
     }

 
So I am writing a test class that is covering the below trigger but it only works if it is created from the New Opportunity button when it is clicked. I am not sure if it is possible but in my test class if I create a contact can I call the button action and check the results from the opportunity is created and inserted? I have not overrode the button or anything, I can't find any information on this. 

trigger fillLeadSource on Opportunity (before update) {
   Set<Id> oppsToFill = new Set<Id>();
    for(Opportunity o : trigger.new){
        if(o.LeadSource == null) {
            oppsToFill.add(o.Id);
        }
    }

    // Now we'll select all possible contacts wasting only 1 query.
    if(!oppsToFill.isEmpty()){
        List<OpportunityContactRole> roles = [SELECT OpportunityId, Contact.Name, Contact.LeadSource, Contact.Lead_Source_Name__c
            FROM OpportunityContactRole
            WHERE isPrimary = true AND Contact.LeadSource != null AND OpportunityId IN :oppsToFill];

        if(!roles.isEmpty()){
            for(OpportunityContactRole ocr : roles){
                Opportunity oppToBeFilled = trigger.newMap.get(ocr.OpportunityId);
                System.debug('Changing lead source on ' + oppToBeFilled.Name + ' from ' + oppToBeFilled.LeadSource + ' to ' + ocr.Contact.LeadSource + ' (thx to ' + ocr.Contact.Name + ' being the Primary Contact).');
                oppToBeFilled.LeadSource = ocr.Contact.LeadSource;
              }
        }
    }
}
As many companies run into issues with lead source and Sales Changing this on opportunities I have been looking for a Trigger that will allow me to auto populate it if it is blank. I plan on removing from the page and allowing the trigger to update it as it will always be blank when an opportunity is created. 

Are sales Reps are forced to create an opportunity from the Contact which gives us the Opportunity Contact Role, ORC. I have the trigger working with lead source but I was asked to add a custom field in it as well and I think I am missing something. Here is the code that I am using if anyone can help that would be great.  Custom Field Name is Lead_Source_Name__c. 

trigger fillLeadSource on Opportunity (before update) {
   Set<Id> oppsToFill = new Set<Id>();
    for(Opportunity o : trigger.new){
        if(o.LeadSource == null) {
            oppsToFill.add(o.Id);
        }
    }

    // Now we'll select all possible contacts wasting only 1 query.
    if(!oppsToFill.isEmpty()){
        List<OpportunityContactRole> roles = [SELECT OpportunityId, Contact.Name, Contact.LeadSource, Contact.Lead_Source_Name__c
            FROM OpportunityContactRole
            WHERE isPrimary = true AND Contact.LeadSource != null AND OpportunityId IN :oppsToFill];

        if(!roles.isEmpty()){
            for(OpportunityContactRole ocr : roles){
                Opportunity oppToBeFilled = trigger.newMap.get(ocr.OpportunityId);
                System.debug('Changing lead source on ' + oppToBeFilled.Name + ' from ' + oppToBeFilled.LeadSource + ' to ' + ocr.Contact.LeadSource + ' (thx to ' + ocr.Contact.Name + ' being the Primary Contact).');
                oppToBeFilled.LeadSource = ocr.Contact.LeadSource;
                oppToBeFilled.Lead_Source_Name__c = orc.Contact.Lead_Source_Name__c;
            }
        }
    }
}
Need help with a test class for the following Class. I am new to development and need to get this class above 75%. I didn't write this class so I am kinda stuck. Any help would be great. 

Class
trigger CreateAssetonClosedWon on Opportunity (after insert, after update) {
  Map<String, AssetRollup__c> rollupMap = AssetRollup__c.getAll();
 
     for(Opportunity o: trigger.new){
      if(o.isWon == true && o.HasOpportunityLineItem == true){
         String opptyId = o.Id;
         OpportunityLineItem[] OLI = [Select UnitPrice, Quantity, PricebookEntry.Product2Id,
                                             TotalPrice,
                                             PricebookEntry.Product2.Name, Description, Converted_to_Asset__c,
                                             PricebookEntry.Product2.Create_Asset__c, PricebookEntry.Product2.Sales_Order_Group__c
                                      From OpportunityLineItem
                                      where OpportunityId = :opptyId
                                        and Converted_to_Asset__c = false
                                        and PricebookEntry.Product2.Create_Asset__c = true];
         Asset[] ast = new Asset[]{};
         Asset hotline;
         Asset a = new Asset();
         for(OpportunityLineItem ol: OLI){
            a = new Asset();
          a.AccountId = o.AccountId;
            a.Product2Id = ol.PricebookEntry.Product2Id;
            a.Quantity__c = ol.Quantity;
            a.Price =  ol.TotalPrice;
            a.PurchaseDate = o.CloseDate;
            a.Renewal_Date__c = o.CloseDate.Month() + '/' + o.CloseDate.Day();
            a.Status = 'Purchased';
            a.Description = ol.Description;
            a.Name = ol.PricebookEntry.Product2.Name;
        // TODO:extend this to support matching on sales order group from AssetRollup__c and build a list of rollups         
        if(ol.PricebookEntry.Product2.Sales_Order_Group__c=='International Hotline'){
          if(hotline == null) {
            hotline = a;
            AssetRollup__c rollup = rollupMap.get(ol.PricebookEntry.Product2.Sales_Order_Group__c);
            if (rollup != null){
              hotline.Name = rollup.Asset_Name__c;
              hotline.Product2Id = rollup.ProductId__c;
            }
          }
          else {
            hotline.Quantity__c += a.Quantity__c;
            hotline.Price += ol.TotalPrice;
          }
        }
        else{
              ast.add(a);
        }
           
            ol.Converted_to_Asset__c = true;
       }
       if(hotline != null) {
         ast.add(hotline);
       }
      update OLI;
      
      insert ast;
     }
    }
}

Test Class


@isTest
Public class testReassignCNO {
    
     static testMethod void testPardotScore() {
    
        Account a = new Account();
        a.name = 'TNW (for Competitor Profile)';
        a.OwnerId = '005A0000000gWDt';
        insert a;
       
        Contact q = new Contact();
        q.FirstName = 'Test';
        q.LastName = 'User 1';
        q.pi__score__c = 20;
        q.accountId = a.Id;
        q.OwnerId = '005A0000000gWDt';
        q.No_Longer_Employed__c = true;
        insert q;
       
         Contact c = new Contact();
        c.FirstName = 'Test2';
        c.LastName = 'User 2';
        c.pi__score__c = 20;
        c.accountId = a.Id;
        c.OwnerId = '005F0000003kNza';
        insert c;
        
        a.assign__c = True;
        update a;
       
        
       
    }
}
I have a trigger and have to change the logic a little check if a number field is Null. I have done some research and everything is telling me to use the IsNull Fuction and it keep getting the error below and Can't figure it out. I have the section of code that is giving me the issue. 

Error Error: Compile Error: Method does not exist or incorrect signature: IsNull(Decimal) at line 3 column 4

trigger AssignTerritoryType on Account (Before insert, Before update) {
    For (Account a :trigger.new){
if(IsNull(a.Fortune_1000_Rank__c) && (a.NumberOfEmployees >= 10000) && (a.Industry != 'Education')==True  ||
   IsNull(a.Fortune_1000_Rank__c) && (a.AnnualRevenue >= 800000000) && (a.Industry != 'Education')==True  ||
    a.Industry == 'Energy' ||
    a.Industry == 'Pharma/BioTech' ||
    a.Industry == 'Fed - Gov'  ||
    a.Fortune_1000_Rank__c <=650 )
    {
  a.Major__c=true;
  a.Mid__c=False;
  a.Inside__c=False;
  a.Inside_small__c=False;
    }
Here is the code that I am using sorry if it is not clean or hard to read new to development and haven't learned how to clean up the mess. 


trigger AssignTerritoryType on Account (before insert, before update) {
For (Account a :trigger.new){
  Set<string> majorIndustries = new Set<string>{'Pharma/BioTech', 'Energy', 'Fed - Gov' ,'State - Mid','Education'};
if ( (a.NumberOfEmployees >= 10000) ||
      (a.AnnualRevenue >= 500000000) ||
   (a.Fortune_500__c = true) ||
   ( (a.Fortune_500_1000__c = True) && (a.NumberOfEmployees >=10000) && (a.AnnualRevenue >= 500000000) ) || //note that even if a.Fortune_500_1000__c = False it'll fall if a.NumberOfEmplyees >=10000 is true or A.AnnualRevenue>=500000000 since it will meet a previous condidtion
   majorIndustries.contains(a.Industry) = 'Pharma/BioTech')
   {
  a.Major__c=true;
    }
if ( ((a.NumberOfEmployees < 10000) && (a.NumberOfEmployees >=4000)) ||
     ((a.AnnualRevenue > 500000000) && (a.AnnualRevenue <=250000000)) ||
     ((a.Fortune_501_1000__c = true) &&(a.NumberOfEmployees > 10000) && (a.AnnualRevenue > 500000000))||
     (majorIndustries.contains(a.Industry) = 'State - mid')||
     ((a.NumberOfEmployees >=8000) && (majorIndustries.contains(a.Industry) = 'Education')
     )
   )
   {  
  a.Mid__c=true;
}
if   ((a.NumberOfEmployees < 4000) && (a.NumberOfEmployees >=1500)
     )
   {
  a.Inside__c=true;
   }
If   ((a.NumberOfEmployees < 4000)
  )
   {
  a.Inside_small__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);
  }
}

}
Not sure why I am getting this looking at the SOQL statement I have the name in the Query, Here is the full error. 

Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, ProjectrollupOLi: execution of AfterUpdate caused by: System.SObjectException: SObject row was retrieved via SOQL without querying the requested field: Opportunity.Communications_Team__c Trigger.ProjectrollupOLi: line 65, column 1: []
Error is in expression '{!doSaveOLI}' in component <apex:commandButton> in page productsearch: Class.ProductSearch.doSaveOLI: line 1016, column 1

Here is the Trigger,

trigger ProjectrollupOLi on OpportunityLineItem (after insert, after update, before delete)

    Set <String> oppIdSet = new Set <String>();

    if(Trigger.isAfter)
        for(OpportunityLineItem oli : Trigger.new)
            oppIdSet.add(oli.OpportunityId);
    if(Trigger.isBefore)
        for(OpportunityLineItem oli : Trigger.old)
            oppIdSet.add(oli.OpportunityId);
    
    Map<Id,Opportunity> oppOldMap = new Map<Id,Opportunity>([Select Id, Implementation_Team__c, Training_Team__c From Opportunity Where Id IN :oppIdSet]);

    Set<String> oppImplementationTeamList = new Set<String>();
    Set<String> oppTrainingTeamList = new Set<String>();
    Set<String> oppCommunicationTeamList = new Set<String>();
        
    List <OpportunityLineItem> oliList = [Select UnitPrice, Quantity, PricebookEntry.Product2Id, TotalPrice,PricebookEntry.Product2.Name, Description,
        Converted_to_Asset__c,Asset__c,PricebookEntry.Product2.Create_Asset__c, PricebookEntry.Product2.Sales_Order_Group__c, OpportunityId From OpportunityLineItem where 
        OpportunityId IN : oppIdSet And (PricebookEntry.Product2.Product_Reporting_Category__c = 'Services' or PricebookEntry.Product2.Name LIKE '%Communications%')];

    for(OpportunityLineItem oli : oliList)
    {
        if(oli.PricebookEntry.Product2.Sales_Order_Group__c == 'Hotline Services' || oli.PricebookEntry.Product2.Sales_Order_Group__c == 'Policy Management Services' || oli.PricebookEntry.Product2.Sales_Order_Group__c == 'Incident Management Services')
        {
            oppImplementationTeamList.add(oli.OpportunityId);
        }
        if(oli.PricebookEntry.Product2.Sales_Order_Group__c == 'ReadyTraining Services')
        {
            oppTrainingTeamList.add(oli.OpportunityId);
        }
        if(oli.pricebookEntry.Product2.Name.Contains('Communications'))
        {
            oppCommunicationTeamList.add(oli.OpportunityId);
        }
    }
    
    Map<Id,Opportunity> updateMap = new Map<Id,Opportunity>();
    
    for(Id oppId : oppIdSet)
    {
        Opportunity opp = new Opportunity(Id = oppId, Implementation_Team__c = false, Training_Team__c = false, Communications_Team__c = false);
        updateMap.put(oppId, opp);
    }
    
    for(Id oppId : oppImplementationTeamList)
    {
        Opportunity opp = updateMap.get(oppId);
        opp.Implementation_Team__c = true;
    }
    
    for(Id oppId : oppTrainingTeamList)
    {
        Opportunity opp = updateMap.get(oppId);
        opp.Training_Team__c = true;
    }
    for(Id oppId : oppCommunicationTeamList)
        {
            Opportunity opp = updateMap.get(oppId);
            opp.Communications_Team__c = true;
        }
    for(Opportunity oppOld : oppOldMap.values())
    {
        Opportunity oppNew = updateMap.get(oppOld.Id);
        if(oppNew.Implementation_Team__c == oppOld.Implementation_Team__c && oppNew.Training_Team__c == oppOld.Training_Team__c && oppNew.Communications_Team__c == oppOld.Communications_Team__c)
            updateMap.remove(oppOld.Id);
    }
    
    List<Opportunity> updateList = updateMap.values();
    
    if(updateList.size()>0)
        update updateList;
}
Hey Guys need another set of eyes on this as I am not sure why this is happening. 

trigger Projectrollup on OpportunityLineItem (after insert, after update, before delete)

    Set oppIdSet = new Set();

    if(Trigger.isAfter)
        for(OpportunityLineItem oli : Trigger.new)
            oppIdSet.add(oli.OpportunityId);
    if(Trigger.isBefore)
        for(OpportunityLineItem oli : Trigger.old)
            oppIdSet.add(oli.OpportunityId);
    
    Map oppOldMap = new Map([Select Id, Implementation_Team__c, Training_Team__c From Opportunity Where Id IN :oppIdSet]);

    Set oppImplementationTeamList = new Set();
    Set oppTrainingTeamList = new Set();
        
    List oliList = [Select UnitPrice, Quantity, PricebookEntry.Product2Id, TotalPrice,PricebookEntry.Product2.Name, Description,
        Converted_to_Asset__c,Asset__c,PricebookEntry.Product2.Create_Asset__c, PricebookEntry.Product2.Sales_Order_Group__c, OpportunityId From OpportunityLineItem where 
        OpportunityId IN : oppIdSet And (PricebookEntry.Product2.Product_Reporting_Category__c = 'Services' or PricebookEntry.Product2.Name LIKE '%Communications%')];

    for(OpportunityLineItem oli : oliList)
    {
        if(oli.PricebookEntry.Product2.Sales_Order_Group__c == 'Hotline Services' || oli.PricebookEntry.Product2.Sales_Order_Group__c == 'Policy Management Services' || oli.PricebookEntry.Product2.Sales_Order_Group__c == 'Incident Management Services')
        {
            oppImplementationTeamList.add(oli.OpportunityId);
        }
        if(oli.PricebookEntry.Product2.Sales_Order_Group__c == 'ReadyTraining Services')
        {
            oppTrainingTeamList.add(oli.OpportunityId);
        }
    }
    
    Map updateMap = new Map();
    
    for(Id oppId : oppIdSet)
    {
        Opportunity opp = new Opportunity(Id = oppId, Implementation_Team__c = false, Training_Team__c = false);
        updateMap.put(oppId, opp);
    }
    
    for(Id oppId : oppImplementationTeamList)
    {
        Opportunity opp = updateMap.get(oppId);
        opp.Implementation_Team__c = true;
    }
    
    for(Id oppId : oppTrainingTeamList)
    {
        Opportunity opp = updateMap.get(oppId);
        opp.Training_Team__c = true;
    }
    
    for(Opportunity oppOld : oppOldMap.values())
    {
        Opportunity oppNew = updateMap.get(oppOld.Id);
        if(oppNew.Implementation_Team__c == oppOld.Implementation_Team__c && oppNew.Training_Team__c == oppOld.Training_Team__c)
            updateMap.remove(oppOld.Id);
    }
    
    List updateList = updateMap.values();
    
    if(updateList.size()>0)
        update updateList;
}
I am not sure how to fix this, Any help would be great. 

trigger Projectrollup on Opportunity (after insert, after update)
{
  Map<Id,Opportunity> oppIds = new Map<Id,Opportunity>();
  List<Opportunity> updateList = new List<Opportunity>();
 
  for(Opportunity o : Trigger.new)
  {
      oppIds.put(o.id,o);
                                        
  }
 
  OpportunityLineItem[] OLI = [Select UnitPrice, Quantity, PricebookEntry.Product2Id, TotalPrice,PricebookEntry.Product2.Name, Description,
                                Converted_to_Asset__c,Asset__c,PricebookEntry.Product2.Create_Asset__c, PricebookEntry.Product2.Sales_Order_Group__c
                               From OpportunityLineItem
                               where OpportunityId IN : oppIds.keySet()
                               And (PricebookEntry.Product2.Product_Reporting_Category__c = 'Services'
                               or PricebookEntry.Product2.Name LIKE '%Communications%')];
 
  for(OpportunityLineItem o : OLI)
  {
    if(o.PricebookEntry.Product2.Sales_Order_Group__c == 'Hotline Services' || o.PricebookEntry.Product2.Sales_Order_Group__c == 'Policy Management Services' || o.PricebookEntry.Product2.Sales_Order_Group__c == 'Incident Management Services')
    {
      Opportunity opp = new Opportunity(id= o.OpportunityId);
      opp.Implementation_Team__c = true;
      updateList.add(opp);
    }
    if(o.PricebookEntry.Product2.Sales_Order_Group__c == 'ReadyTraining Services')
    {
      Opportunity opp = new Opportunity(id=o.OpportunityId);
      opp.Training_Team__c = true;
      updateList.add(opp);
    }
   }
 
  if(updateList.size()>0)
  {
    update updateList;
  }
}
 
I need to update some custom fields on the opportunity when certin products are selected. I just need the starting point to update the opportunity I believe that everything else is correct. 

If Pricebook2.Product2.Sales_Order_Group__c = 'Hotline Services' OR 'Policy Management Services' OR 'Incident Management Services' I need to update Implementation_Team__c to True 
Else if Pricebook2.Product2.Sales_Order_Group__c = 'ReadyTraining Services' I need to Update Training_Team__c to True

There are a couple more values but I am sure that I can figure that part out with a sample. Also I don't think the ELSE IF is right becuase it should be possible that both are selected. 

Any help would be greatly appricated. Below is what I have started but not sure if it is all correct. 


trigger Projectrollup on Opportunity (after insert, after update) {
    Map<PricebookEntry.Product2.Name,OpportunityLineItem> prod = new map<PricebookEntry.Product2.Name,OpportunityLineItem>();
        for(Opportunity o: trigger.new){
            if(o.HasOpportunityLineItem == true){
                string opptyId = o.id;
                OpportunityLineItem[] OLI = [Select UnitPrice, Quantity, PricebookEntry.Product2Id, 
                                             TotalPrice,
                                             PricebookEntry.Product2.Name, Description, Converted_to_Asset__c,Asset__c,
                                             PricebookEntry.Product2.Create_Asset__c, PricebookEntry.Product2.Sales_Order_Group__c
                                      From OpportunityLineItem 
                                      where OpportunityId = :opptyId
                                      And   PricebookEntry.Product2.Product_Reporting_Category__c = 'Services'];
 
The following trigger is not eveluating past the Prospect Major for some reason. If I comment out the major assignment I get Mid for an account that should be Inside. I am hoping I am missing something small as I need to reassign accounts this evening after 5pm EST. I am sure there is a better way to do it so I am sorry for all the over code. 

trigger AssignTerritoryType on Account (Before insert, Before update) {
    For (Account a :trigger.new){
    IF((a.Current_Account_Status__c == 'Customer' || 
        a.Current_Account_Status__c == 'Customer - In Play') && 
            a.NumberOfEmployees >= 10000 )
            { a.Major__c=true;
              a.Mid__c=False;
              a.Inside__c=False;
              }
    else IF((a.Current_Account_Status__c == 'Customer' || 
             a.Current_Account_Status__c == 'Customer - In Play') && 
                 (a.NumberOfEmployees > 2000 && 
                  a.NumberOfEmployees <= 10000))
            { a.Major__c=False;
              a.Mid__c=True;
              a.Inside__c=False;
             }          
    else IF((a.Current_Account_Status__c == 'Customer' || 
             a.Current_Account_Status__c == 'Customer - In Play') && 
                (a.NumberOfEmployees > 0 && 
                 a.NumberOfEmployees <= 2000))
            {a.Major__c=False;
             a.Mid__c=False;
             a.Inside__c=True;
            }         
    else if((a.Current_Account_Status__c == 'Prospect' || 
             a.Current_Account_Status__c == 'Prospect - In Play' &&
                 (a.Fortune_1000_Rank__c==NULL) &&
                 (a.NumberOfEmployees >= 9000) && 
                 (a.Industry != 'Education')==True)  ||
                    (a.Current_Account_Status__c == 'Prospect' || 
                     a.Current_Account_Status__c == 'Prospect - In Play' &&
                    (a.Fortune_1000_Rank__c==Null) && 
                     (a.AnnualRevenue >= 1000000000) && 
                     (a.Industry != 'Education')==True)  ||
                          (a.Current_Account_Status__c == 'Prospect' || 
                           a.Current_Account_Status__c == 'Prospect - In Play' &&
                           a.Industry == 'Pharma/BioTech') ||
                                (a.Current_Account_Status__c == 'Prospect' || 
                                 a.Current_Account_Status__c == 'Prospect - In Play' &&
                                 a.Industry == 'Fed - Gov')  ||
                                    (a.Current_Account_Status__c == 'Prospect' || 
                                     a.Current_Account_Status__c == 'Prospect - In Play' &&
                                     a.Fortune_1000_Rank__c <=750 ))
            {
              a.Major__c=true;
              a.Mid__c=False;
              a.Inside__c=False;
              }

    else if ((a.Current_Account_Status__c == 'Prospect' || 
              a.Current_Account_Status__c == 'Prospect - In Play' &&
             (a.NumberOfEmployees < 9000) && 
             (a.NumberOfEmployees >=3000) &&
             (a.Industry != 'Education')==True ) ||
                     (a.Current_Account_Status__c == 'Prospect' || 
                      a.Current_Account_Status__c == 'Prospect - In Play' &&
                     (a.AnnualRevenue < 1000000000) && 
                     (a.AnnualRevenue >=500000000)) ||
                          (a.Current_Account_Status__c == 'Prospect' || 
                           a.Current_Account_Status__c == 'Prospect - In Play' &&
                          (a.Fortune_1000_Rank__c >=751)) ||
                             (a.Current_Account_Status__c == 'Prospect' || 
                              a.Current_Account_Status__c == 'Prospect - In Play' &&
                             (a.NumberOfEmployees >=8000) && 
                             (a.Industry == 'Education')==True) ||
                                   (a.Current_Account_Status__c == 'Prospect' || 
                                    a.Current_Account_Status__c == 'Prospect - In Play' &&
                                    a.Industry == 'State -Gov')
           )
            {a.Major__c=False;
             a.Mid__c=True;
             a.Inside__c=False;
           }

    else   
            {a.Major__c=False;
             a.Mid__c=False;
             a.Inside__c=True;
             }
       }
}
I am writing a test class for the below APEX trigger and running into something that I have never covered before and could use some help in understanding how to cover. 

trigger fillLeadSource on Opportunity (before update) {
   Set<Id> oppsToFill = new Set<Id>();
    for(Opportunity o : trigger.new){
        if(o.LeadSource == null) {
            oppsToFill.add(o.Id);
        }
    }

    // Now we'll select all possible contacts wasting only 1 query.
    if(!oppsToFill.isEmpty()){
        List<OpportunityContactRole> roles = [SELECT OpportunityId, Contact.Name, Contact.LeadSource, Contact.Lead_Source_Name__c
            FROM OpportunityContactRole
            WHERE isPrimary = true AND Contact.LeadSource != null AND OpportunityId IN :oppsToFill];

        if(!roles.isEmpty()){
            for(OpportunityContactRole ocr : roles){
                Opportunity oppToBeFilled = trigger.newMap.get(ocr.OpportunityId);
                System.debug('Changing lead source on ' + oppToBeFilled.Name + ' from ' + oppToBeFilled.LeadSource + ' to ' + ocr.Contact.LeadSource + ' (thx to ' + ocr.Contact.Name + ' being the Primary Contact).');
                oppToBeFilled.LeadSource = ocr.Contact.LeadSource;
                oppToBeFilled.Lead_Source_Name__c = orc.Contact.Lead_Source_Name__c;
            }
        }
    }
}


Lines I need help Covering 

            for(OpportunityContactRole ocr : roles){
                Opportunity oppToBeFilled = trigger.newMap.get(ocr.OpportunityId);
                System.debug('Changing lead source on ' + oppToBeFilled.Name + ' from ' + oppToBeFilled.LeadSource + ' to ' + ocr.Contact.LeadSource + ' (thx to ' + ocr.Contact.Name + ' being the Primary Contact).');
                oppToBeFilled.LeadSource = ocr.Contact.LeadSource;

TEST CLASS
@isTest
private class triggerfillLeadSource {
     
     static testMethod void fillLeadSource() {
     
        Account a = new Account();
        a.name = 'TNW (for Competitor Profile)';
        insert a;
        
        Contact c = new Contact();
        c.FirstName = 'Test';
        c.LastName = 'User 1';
        c.pi__score__c = 20;
        c.accountId = a.Id;
        c.LeadSource = 'Admin';
        insert c;
        
        c.pi__score__c = 30;
        update c;
        
        Delete c;
         
        Database.undelete(c.id);
        
        Asset ass = new Asset();
        ass.name = 'test Asset';
        ass.Price = 100;
        ass.Status = 'Purchased';
        ass.accountid = a.Id;
        insert ass;
        
        ass.price = 200;
        update ass;
        
        delete ass;
        
        Database.Undelete(ass.Id);
         
        Opportunity o = New Opportunity();
         o.Name = 'test';
         o.AccountId = a.Id;
         o.CloseDate = system.today();
         o.StageName = '0. Sales Ready';
         o.Type = 'New';
         o.LeadSource ='Admin';
         Insert o;
         
         OpportunityContactRole ocr = New OpportunityContactRole();
         ocr.opportunityId = o.Id;
         ocr.ContactId = c.Id;
         ocr.IsPrimary = True;
         insert ocr;
         
         Opportunity opp = [SELECT Leadsource,Name,ID from Opportunity where ID=:o.Id];
         System.assertEquals(c.LeadSource,opp.LeadSource);
       }
     }

 
As many companies run into issues with lead source and Sales Changing this on opportunities I have been looking for a Trigger that will allow me to auto populate it if it is blank. I plan on removing from the page and allowing the trigger to update it as it will always be blank when an opportunity is created. 

Are sales Reps are forced to create an opportunity from the Contact which gives us the Opportunity Contact Role, ORC. I have the trigger working with lead source but I was asked to add a custom field in it as well and I think I am missing something. Here is the code that I am using if anyone can help that would be great.  Custom Field Name is Lead_Source_Name__c. 

trigger fillLeadSource on Opportunity (before update) {
   Set<Id> oppsToFill = new Set<Id>();
    for(Opportunity o : trigger.new){
        if(o.LeadSource == null) {
            oppsToFill.add(o.Id);
        }
    }

    // Now we'll select all possible contacts wasting only 1 query.
    if(!oppsToFill.isEmpty()){
        List<OpportunityContactRole> roles = [SELECT OpportunityId, Contact.Name, Contact.LeadSource, Contact.Lead_Source_Name__c
            FROM OpportunityContactRole
            WHERE isPrimary = true AND Contact.LeadSource != null AND OpportunityId IN :oppsToFill];

        if(!roles.isEmpty()){
            for(OpportunityContactRole ocr : roles){
                Opportunity oppToBeFilled = trigger.newMap.get(ocr.OpportunityId);
                System.debug('Changing lead source on ' + oppToBeFilled.Name + ' from ' + oppToBeFilled.LeadSource + ' to ' + ocr.Contact.LeadSource + ' (thx to ' + ocr.Contact.Name + ' being the Primary Contact).');
                oppToBeFilled.LeadSource = ocr.Contact.LeadSource;
                oppToBeFilled.Lead_Source_Name__c = orc.Contact.Lead_Source_Name__c;
            }
        }
    }
}
Need help with a test class for the following Class. I am new to development and need to get this class above 75%. I didn't write this class so I am kinda stuck. Any help would be great. 

Class
trigger CreateAssetonClosedWon on Opportunity (after insert, after update) {
  Map<String, AssetRollup__c> rollupMap = AssetRollup__c.getAll();
 
     for(Opportunity o: trigger.new){
      if(o.isWon == true && o.HasOpportunityLineItem == true){
         String opptyId = o.Id;
         OpportunityLineItem[] OLI = [Select UnitPrice, Quantity, PricebookEntry.Product2Id,
                                             TotalPrice,
                                             PricebookEntry.Product2.Name, Description, Converted_to_Asset__c,
                                             PricebookEntry.Product2.Create_Asset__c, PricebookEntry.Product2.Sales_Order_Group__c
                                      From OpportunityLineItem
                                      where OpportunityId = :opptyId
                                        and Converted_to_Asset__c = false
                                        and PricebookEntry.Product2.Create_Asset__c = true];
         Asset[] ast = new Asset[]{};
         Asset hotline;
         Asset a = new Asset();
         for(OpportunityLineItem ol: OLI){
            a = new Asset();
          a.AccountId = o.AccountId;
            a.Product2Id = ol.PricebookEntry.Product2Id;
            a.Quantity__c = ol.Quantity;
            a.Price =  ol.TotalPrice;
            a.PurchaseDate = o.CloseDate;
            a.Renewal_Date__c = o.CloseDate.Month() + '/' + o.CloseDate.Day();
            a.Status = 'Purchased';
            a.Description = ol.Description;
            a.Name = ol.PricebookEntry.Product2.Name;
        // TODO:extend this to support matching on sales order group from AssetRollup__c and build a list of rollups         
        if(ol.PricebookEntry.Product2.Sales_Order_Group__c=='International Hotline'){
          if(hotline == null) {
            hotline = a;
            AssetRollup__c rollup = rollupMap.get(ol.PricebookEntry.Product2.Sales_Order_Group__c);
            if (rollup != null){
              hotline.Name = rollup.Asset_Name__c;
              hotline.Product2Id = rollup.ProductId__c;
            }
          }
          else {
            hotline.Quantity__c += a.Quantity__c;
            hotline.Price += ol.TotalPrice;
          }
        }
        else{
              ast.add(a);
        }
           
            ol.Converted_to_Asset__c = true;
       }
       if(hotline != null) {
         ast.add(hotline);
       }
      update OLI;
      
      insert ast;
     }
    }
}

Test Class


@isTest
Public class testReassignCNO {
    
     static testMethod void testPardotScore() {
    
        Account a = new Account();
        a.name = 'TNW (for Competitor Profile)';
        a.OwnerId = '005A0000000gWDt';
        insert a;
       
        Contact q = new Contact();
        q.FirstName = 'Test';
        q.LastName = 'User 1';
        q.pi__score__c = 20;
        q.accountId = a.Id;
        q.OwnerId = '005A0000000gWDt';
        q.No_Longer_Employed__c = true;
        insert q;
       
         Contact c = new Contact();
        c.FirstName = 'Test2';
        c.LastName = 'User 2';
        c.pi__score__c = 20;
        c.accountId = a.Id;
        c.OwnerId = '005F0000003kNza';
        insert c;
        
        a.assign__c = True;
        update a;
       
        
       
    }
}
Here is the code that I am using sorry if it is not clean or hard to read new to development and haven't learned how to clean up the mess. 


trigger AssignTerritoryType on Account (before insert, before update) {
For (Account a :trigger.new){
  Set<string> majorIndustries = new Set<string>{'Pharma/BioTech', 'Energy', 'Fed - Gov' ,'State - Mid','Education'};
if ( (a.NumberOfEmployees >= 10000) ||
      (a.AnnualRevenue >= 500000000) ||
   (a.Fortune_500__c = true) ||
   ( (a.Fortune_500_1000__c = True) && (a.NumberOfEmployees >=10000) && (a.AnnualRevenue >= 500000000) ) || //note that even if a.Fortune_500_1000__c = False it'll fall if a.NumberOfEmplyees >=10000 is true or A.AnnualRevenue>=500000000 since it will meet a previous condidtion
   majorIndustries.contains(a.Industry) = 'Pharma/BioTech')
   {
  a.Major__c=true;
    }
if ( ((a.NumberOfEmployees < 10000) && (a.NumberOfEmployees >=4000)) ||
     ((a.AnnualRevenue > 500000000) && (a.AnnualRevenue <=250000000)) ||
     ((a.Fortune_501_1000__c = true) &&(a.NumberOfEmployees > 10000) && (a.AnnualRevenue > 500000000))||
     (majorIndustries.contains(a.Industry) = 'State - mid')||
     ((a.NumberOfEmployees >=8000) && (majorIndustries.contains(a.Industry) = 'Education')
     )
   )
   {  
  a.Mid__c=true;
}
if   ((a.NumberOfEmployees < 4000) && (a.NumberOfEmployees >=1500)
     )
   {
  a.Inside__c=true;
   }
If   ((a.NumberOfEmployees < 4000)
  )
   {
  a.Inside_small__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);
  }
}

}