• Jim Montgomery
  • NEWBIE
  • 140 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 32
    Questions
  • 41
    Replies
public class CaseAddedProducts {
    public List<WrapperClass> listWrapper {get;set;}
    public Boolean allBool {get;set;}
    public  String caseID {get;set;}
    public CaseAddedProducts() {
    String accountID = System.currentPageReference().getParameters().get('accountID');
    caseID = System.currentPagereference().getParameters().get('caseID'); 
        listWrapper = new List<WrapperClass>();
        List<product> listprd = [SELECT Id, productcode, productname,productfamily,erp__c
        FROM product where isactive = true];
        if(listprd.size() > 0) {
            for(product prd : listprd) {
                listWrapper.add(new WrapperClass(prd));
            }
        }
    }
    
    public class WrapperClass {
        public Boolean checked {get;set;}
        public Product prd {get;set;}
        public WrapperClass(product prd) {
            this.prd = prd;
        }
    }
    
     public PageReference save()
    {
    PageReference caserec = new PageReference('/'+caseID);
    caserec.setredirect(true);
    return caserec;
    }
    
    public void add() {
        List<product> listprdforAdd = new List<product>();
        List<WrapperClass> listTempWrapper = new List<WrapperClass>();
        for(WrapperClass w : listWrapper) {
            if(w.checked) {
                listprdforAdd.add(w.prd);
            } 
        }
        //insert listWrapper into case_cancelled_inventory__c
        List<case_added_inventory__c> listCaseAddedInventory = new List<case_Added_inventory__c>();
   for(aproduct objprd : listprdforAdd){
    case_added_inventory__c objCaseAddedInventory = new case_added_inventory__c();     
    objCaseAddedInventory.Product_Code__c = objprd.productcode;
    objCaseAddedInventory.Product_Name__c = objprd.productname;
        objCaseAddedInventory.case__c = caseID;
    listCaseAddedInventory.add(objCaseAddedInventory);   
   }
   if(listCaseAddedInventory != null && listCaseAddedInventory.size() > 0)
    insert listAddedCaseInventory;
  //insert listWrapper into case_cancelled_inventory__c Ends

 
    }
    
    public void selectAll() {
        if(allBool) {
            for(WrapperClass w : listWrapper) {
                w.checked = true;
            }
        } else {
            for(WrapperClass w : listWrapper) {
                w.checked = false;
            }
        }
    }
}
Too many soql errors trigger msa data line 73

Getting error on this trigger fro one test class, but works fine from another test class.
trigger MSAData on Account (before insert,before update) {  
               Trigger

Map<String,String> MSALookup = new Map<String,String>();
  Set<String> AZipCode = new Set<String>();   
if(trigger.IsInsert){
 for(Account A:Trigger.new) {
    AZipCode.add(A.billingpostalcode);
 } 
 for(naics_code__c NA:
    [SELECT      zip_code__c, msa_code__c
     FROM        naics_code__c
     WHERE       zip_code__c IN :AZipCode]) {
    MSALookup.put(NA.zip_code__c,NA.msa_code__c);
  }
  for(Account A:Trigger.new) {
      if(MSALookup.containsKey(A.billingpostalcode)) {
      A.d_B_msa_code__c = MSALookup.get(A.billingpostalcode);
      }
  }    
    for(Account A:Trigger.new) {    
        AZipCode.add(A.billingpostalcode);
    }    
    for(naics_code__c NA:
    [SELECT      zip_code__c, msa_name__c
     FROM        naics_code__c
     WHERE       zip_code__c IN :AZipCode]) {
    MSALookup.put(NA.zip_code__c,NA.msa_name__c);
  }
  for(Account A:Trigger.new) {
      if(MSALookup.containsKey(A.billingpostalcode)) {
      A.d_B_msa_description__c = MSALookup.get(A.billingpostalcode);
      }
  }
}
if(trigger.isUpdate){    
    for(Account acct:trigger.new){
        account oldAcct= Trigger.oldmap.get(Acct.Id);
    if (oldacct.BillingPostalCode<>Acct.BillingPostalCode){
        AZipCode.add(acct.billingpostalcode);
        } 
    }
    for(naics_code__c NA:
    [SELECT      zip_code__c, msa_name__c
     FROM        naics_code__c
     WHERE       zip_code__c IN :AZipCode]) {
    MSALookup.put(NA.zip_code__c,NA.msa_name__c);
  }  
  for(Account A:Trigger.new) {
      if(MSALookup.containsKey(A.billingpostalcode)) {
      A.d_B_msa_description__c = MSALookup.get(A.billingpostalcode);
      }
  }
    for(Account A:Trigger.new) {
            AZipCode.add(A.billingpostalcode);  
 } 
 for(naics_code__c NA:
    [SELECT      zip_code__c, msa_code__c
     FROM        naics_code__c
     WHERE       zip_code__c IN :AZipCode]) {
    MSALookup.put(NA.zip_code__c,NA.msa_code__c);
  }
  for(Account A:Trigger.new) {
      if(MSALookup.containsKey(A.billingpostalcode)) {
      A.d_B_msa_code__c = MSALookup.get(A.billingpostalcode);
      }
  }
}
}

Test Class
@isTest 
private class TestTaskEventRollup_RecordType {

    static testMethod void InsertTask() {

Account A = new Account(
            Name = 'myAcct', 
            BillingStreet='25 Upland Drive',
            BillingPostalCode='94127',
            BillingCountry='United States',
            BillingCity='San Francisco',
            recordtypeid = '012i0000000Ou0CAAS',
            software_owner__C = '005i0000001gISQAA2' );
        insert A;
       

Campaign Cam = new Campaign(
        name = '18--support-phone inbound-torrance',
        type = 'Direct mail',
        isactive = true);
        insert Cam;
        
 Contact c = new Contact(
        firstname = 'Jim', lastname = 'Montgomery');
        Insert c;

 Opportunity O = new Opportunity(
        Name = 'TestOpp',
        accountId = A.Id,
        type = 'New to Existing',
        Closedate = Date.today().addYears(1),
        stagename = '1. Gain Access',
        product_category__c = 'Med/Large Software',
        Amount = 1.00,
        product_Sub_Category__c = 'Tax');
        insert O;
        
       Task tsk = New Task(
Type = 'Email',
WhatId = A.Id,

Subject = 'Call'
);
insert tsk;

Task tsk2 = New Task(
Type = 'Email',
whatId = A.Id,
Subject = 'Call'
);
insert tsk2;

Task tsk3 = New Task(
Type = 'Email',
whatId = A.Id,
Subject = 'Call'
);
insert tsk3;
Event Evt = New Event(
OwnerId = '005i0000001gISQAA2',
subject = 'Demonstration',
event_type__c = 'Demo - Professional',
whatId = A.Id,
no_sa_needed__c = true,
startdatetime = datetime.newInstance(2018, 9, 15, 12, 30, 0),
enddatetime = datetime.newInstance(2018, 9, 15, 12, 35, 0));
insert Evt;

Event Evt1 = New Event(
OwnerId = '005i0000001gISQAA2',
subject = 'Demonstration',
event_type__c = 'Conference Call',
whatId = A.Id,
no_sa_needed__c = true,
startdatetime = datetime.newInstance(2018, 9, 15, 12, 30, 0),
enddatetime = datetime.newInstance(2018, 9, 15, 12, 35, 0));
insert Evt1;

Event Evt2 = New Event(
OwnerId = '005i0000001gISQAA2',
subject = 'Demonstration',
event_type__c = 'In_Person Meeting',
whatId = A.Id,
no_sa_needed__c = true,
startdatetime = datetime.newInstance(2018, 9, 15, 12, 30, 0),
enddatetime = datetime.newInstance(2018, 9, 15, 12, 35, 0));
insert Evt2;
}
}
Works on update, but not o insert

Works fine on update, but not on insert. Record Type is not stamped on the activity.


trigger TaskAccountTypeContact on Task (before insert, before update) {
   For (Task T : trigger.new){            
            string WhoID = t.WhoID;
    if(t.WhoId!=NULL){
   if(WhoID.startswith('0')){
   if(T.AccountID!=NULL){
    Account a = [select id,recordtypeid from Account where id =:T.AccountId]; 
if(a.recordtypeid == '012i0000000Ou0CAAS'){
        t.Account_record_Type__c ='Customer Account';                
        }
        else
        if(a.recordtypeid == '012i0000000Ou0EAAS'){
        t.Account_record_Type__c = 'Prospect Account';                
        }
        else
        if(a.recordtypeid == '012i0000000Ou0DAAS'){
        t.Account_record_Type__c = 'Partner Account';               
        }
}
}
}
}
}
I have a trigger on task that will update the task with the accounts record type on insertion.
I also need to do this on an update, but get the "maximum Trigger Depth" error when adding before update to the trigger.

trigger TaskAccountType on Task (after insert) {
    Task T = [select Id,WhatId,subject from task where Id = :trigger.new[0].Id];
    if(trigger.new[0].Id!=null){
    string WhatId = t.WhatId;
    
    if(t.WhatId!=NULL){
   if(WhatId.startswith('0')){
    Account a = [select id,recordtypeid from Account where id =: trigger.new[0].AccountId];
if(trigger.new[0].AccountId!=null){  
if(a.recordtypeid == '012i0000000Ou0CAAS'){
        t.Account_record_Type__c ='Customer Account'; 
        update T;       
        }
        else
        if(a.recordtypeid == '012i0000000Ou0EAAS'){
        t.Account_record_Type__c = 'Prospect Account';  
        update T;      
        }
        else
        if(a.recordtypeid == '012i0000000Ou0DAAS'){
        t.Account_record_Type__c = 'Partner Account';  
        update T;      
        }
}
}
}
}
}
I am trying to add a field from the account when creating a task on an opportunity or account, or contact. I should be able to access the AccountId field on the task record to pull this,.

trigger AccountRecordType on Task (before insert, before update) {
for (Task T : trigger.New){
Account a = [select id,recordtypeid from Account where id =: trigger.new[0].AccountId];    
if(a.recordtypeid == '012i0000000Ou0CAAS'){
        t.Account_record_Type__c = 'Customer Account';        
        }
        if(a.recordtypeid == '012i0000000Ou0EAAS'){
        t.Account_record_Type__c = 'Prospect Account';        
        }
        if(a.recordtypeid == '012i0000000Ou0DAAS'){
        t.Account_record_Type__c = 'Partner Account Account';        
        }
}
}
Cannot find out why on a delete the checkbox is not being updated to false.

trigger HasSFTRPromotion on Quote_Promotion__c (after insert, after update, before delete) {
Map<ID, Apttus_Proposal__Proposal__c> parentProposal = new Map<ID, Apttus_Proposal__Proposal__c>();
    List<Id> listIds = new List<Id>();
    List<Id> LineItems = new List<Id>();
    
    If(trigger.Isdelete){
for (Quote_Promotion__c childObj : Trigger.old) {
        listIds.add(childObj.Quote_Proposal__c);
        LineItems.add(childObj.Id);
    }
  
    parentProposal = new Map<Id, Apttus_Proposal__Proposal__c>([SELECT id,HasSFTRPromotion__c,(Select id from Promotion_Groups__r where Promotion_Code__c IN('26645', '26646', '26647', '26648', '26649', '26650', '26651', '26652', '26653', '26654', '26655', '26656'
)) FROM Apttus_Proposal__Proposal__c WHERE ID IN :listIds]);
    
    for (Quote_Promotion__c QPromo: Trigger.old){
         Apttus_Proposal__Proposal__c myParentProposal = parentProposal.get(QPromo.Quote_Proposal__c);
        if(parentProposal.containsKey(QPromo.Quote_Proposal__c) && parentProposal.get(QPromo.Quote_Proposal__c).Promotion_Groups__r.size() > 0)
        {
            myParentProposal.HasSFTRPromotion__c = true;
        }
        else
        {
       myParentProposal.HasSFTRPromotion__c = false;
       }
    }
    update parentProposal.values();
    }
Here is my trigger and test class. I can create an account with the exact same properties as they account in the test class, and it works fine. But thr test class fails with this error.
Error:
System.DmlException: Update failed. First exception on row 0 with id 0010x00000FTfC0AAL; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, RCLeadAutoCreateFromAccount: execution of AfterUpdate

caused by: System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_EXECUTE_FLOW_TRIGGER, The record couldn’t be saved because it failed to trigger a flow. A flow trigger failed to execute the flow with version ID 3010x0000000W9o. Flow error messages: <b>An unhandled fault has occurred in this flow</b><br>An unhandled fault has occurred while processing the flow. Please contact your system administrator for more information. Contact your administrator for help.: []

Trigger.RCLeadAutoCreateFromAccount: line 24, column 1: []
Stack TraceClass.TestRCLeadAutoCreate.insertAccount: line 27, column 1


Trigger:
trigger RCLeadAutoCreateFromAccount on Account (after update) {
    for (Account A:Trigger.New){
    String Name = UserInfo.getName();
         Account oldAccount = Trigger.oldMap.get(A.Id);
        if(oldAccount.RC_Lead_TimeStamp__c != A.RC_Lead_TimeStamp__c){
        Campaign C = [select id from campaign where name = '18--support-phone inbound-torrance'];
              Lead L = new Lead(
                company = A.name,
                status = 'Not Started',
                lastname = 'RC Lead',
                rating = 'Hot',
                market_segment__c = A.Market_Segment__c,
                market_sub_segment__c = A.Market_Sub_Segment__c,
                street = a.billingstreet,
                city = a.billingcity,
                state = a.billingstate,
                PostalCode = a.BillingPostalCode,
                named_account_type__c = a.Named_Account_Type__c,
                related_account__c = a.Id,
                description = a.rc_lead_comments__c,
                rc_lead_product_interest__c = a.rc_lead_product_interest_MS__c);
            insert L;
            if(A.Named_Account_Type__c == 'Small Firm Tax Customer'){
                L.small_market_N2E__c = True;
                update L;
            }
            campaignmember CM = new campaignmember(
                campaignID = C.Id, 
                comments__c = a.rc_lead_comments__c,             
                leadID = L.ID
                    );
                insert cm;
                             
        }
        
    
    }
}

Test Class:
@isTest 
private class TestRCLeadAutoCreate {

    static testMethod void insertAccount() {
    string name = 'Jim Montgomery';
   Account A = new Account(
            Name = 'myAcct', 
            BillingStreet='25 Upland Drive',
            BillingPostalCode='94127',
            BillingCountry='United States',
            BillingCity='San Francisco',
            market_segment__c = 'Accounting Firms',
            market_sub_segment__c = 'Sole Proprietor',
            billingstate = 'CA',
            named_account_type__c = 'Strategic',
            rc_lead_comments__c = 'Test',
            rc_lead_product_interest_ms__c = 'Pfx Tax'
            );
        insert A;
        Campaign Cam = new Campaign(
        name = '18--support-phone inbound-torrance',
        type = 'Direct mail',
        isactive = true);
        insert Cam;
        
        a.rc_lead_timestamp__c = system.now();
        update a;
        }
        }
Not sure where this is erroring out.

trigger MSAData on Account (before insert,before update) { 
    for (account Acc:trigger.new){       
               
Map<String,String> MSALookup = new Map<String,String>();
  Set<String> AZipCode = new Set<String>();  
  
        
if(trigger.IsInsert){
 for(Account A:Trigger.new) {
    AZipCode.add(A.billingpostalcode);
  for(naics_code__c NA:
    [SELECT      zip_code__c, msa_code__c
     FROM        naics_code__c
     WHERE       zip_code__c IN :AZipCode]) {

    MSALookup.put(NA.zip_code__c,NA.msa_code__c);
  }
 }

  for(Account A:Trigger.new) {
      if(MSALookup.containsKey(A.billingpostalcode)) {
      A.d_B_msa_code__c = MSALookup.get(A.billingpostalcode);
      }
  }
    
    for(Account A:Trigger.new) {    
    AZipCode.add(A.billingpostalcode);
        
 for(naics_code__c NA:
    [SELECT      zip_code__c, msa_name__c
     FROM        naics_code__c
     WHERE       zip_code__c IN :AZipCode]) {

    MSALookup.put(NA.zip_code__c,NA.msa_name__c);
  }
 }

  for(Account A:Trigger.new) {
      if(MSALookup.containsKey(A.billingpostalcode)) {
      A.d_B_msa_description__c = MSALookup.get(A.billingpostalcode);
      }
  }
}
else                    

    
if(trigger.isUpdate){    

    for(Account acct:trigger.new){
        account oldAcct= Trigger.oldmap.get(Acct.Id);
    if (oldacct.BillingPostalCode<>Acct.BillingPostalCode){
    
    for(Account A:Trigger.new) {
        
       
           
    AZipCode.add(A.billingpostalcode);
       
 for(naics_code__c NA:
    [SELECT      zip_code__c, msa_name__c
     FROM        naics_code__c
     WHERE       zip_code__c IN :AZipCode]) {

    MSALookup.put(NA.zip_code__c,NA.msa_name__c);
  }
    }
    
  for(Account A:Trigger.new) {
      if(MSALookup.containsKey(A.billingpostalcode)) {
      A.d_B_msa_description__c = MSALookup.get(A.billingpostalcode);
      }
  }
    for(Account A:Trigger.new) {
        
    AZipCode.add(A.billingpostalcode);
  for(naics_code__c NA:
    [SELECT      zip_code__c, msa_code__c
     FROM        naics_code__c
     WHERE       zip_code__c IN :AZipCode]) {

    MSALookup.put(NA.zip_code__c,NA.msa_code__c);
  }
 }

  for(Account A:Trigger.new) {
      if(MSALookup.containsKey(A.billingpostalcode)) {
      A.d_B_msa_code__c = MSALookup.get(A.billingpostalcode);
      }
  }
}
}
}
}
}
I am getting error Invalid Type: listAIRforAdd line 39
Code:
public class CaseInventory {

    public List<WrapperClass> listWrapper {get;set;}
    public Boolean allBool {get;set;}
    
    public CaseInventory() {
    String accountID = System.currentPageReference().getParameters().get('accountID');
    String caseID = System.currentPagereference().getParameters().get('caseID'); 
        listWrapper = new List<WrapperClass>();
        List<ams_inventory_rollup__c> listAIR = [SELECT Id, Name, product_name__c,quantity__c,pfx_account_number__c 
        FROM ams_inventory_rollup__c where AccountId__c = :accountId];
        if(listAIR.size() > 0) {
            for(ams_inventory_rollup__c air : listAIR) {
                listWrapper.add(new WrapperClass(air));
            }
        }
    }
    
    public class WrapperClass {
        public Boolean checked {get;set;}
        public ams_inventory_rollup__c air {get;set;}
        public WrapperClass(ams_inventory_rollup__c air) {
            this.air = air;
        }
    }
    
    public void add() {
        List<ams_inventory_rollup__c> listAIRforAdd = new List<ams_inventory_rollup__c>();
        List<WrapperClass> listTempWrapper = new List<WrapperClass>();
        for(WrapperClass w : listWrapper) {
            if(w.checked) {
                listAIRforAdd.add(w.air);
            } 
        }
        
    }
  List<Case_Inventories__c> CaseINVs = new List<case_Inventories__c>();
    
    for(listAIRforAdd wrAIR:listWrapper){
    case_inventories__c CI = new case_inventories__c();
    ci.product_code__c = wrAIR.name;
    ci.product_name__c = wrAIR.product_name__c;
    ci.quantity__c = wrAIR.quantity;
    CaseINVs.add(wrAIR);
    }
    Insert CaseINVs;
    
    public void selectAll() {
        if(allBool) {
            for(WrapperClass w : listWrapper) {
                w.checked = true;
            }
        } else {
            for(WrapperClass w : listWrapper) {
                w.checked = false;
            }
        }
    }
}
 
I have this controller<

public class AIRList {   
    public ApexPages.StandardSetController setAIR {
            get {
            if(setAIR == null) {
String accountID = System.currentPageReference().getParameters().get('accountID');
String caseID = System.currentPagereference().getParameters().get('caseID');
                setAIR = new ApexPages.StandardSetController(Database.getQueryLocator(
                    [SELECT id,Name, product_name__c,quantity__c,pfx_account_number__c FROM ams_inventory_rollup__c where accountID__c = :accountId]));

            }
            return setAIR;
        }
        set;
    }
        public List<AMS_Inventory_Rollup__c> getAMSInventories() {
        return (List<AMS_Inventory_Rollup__c>) setAIR.getRecords();
    }
}
That populates this VF page, 

<apex:page controller="AIRList"> <apex:form > <apex:pageBlock > <apex:pageBlockTable value="{!AMSInventories}" var="a"> <apex:column > <apex:inputCheckbox /> </apex:column> <apex:column value="{!a.Name}"/> <apex:column value="{!a.Product_Name__c}"/> <apex:column value="{!a.Quantity__c}"/> <apex:column value="{!a.PFX_Account_Number__c}"/> </apex:pageBlockTable> </apex:pageBlock> </apex:form> </apex:page>

I need to take the selected items form the page, and add them to a case related object/List. Case_cancelled_Inventories that is the child in a masetr/detail relationship to case.
Invalid bind expression type of Case for column of type Id line 9

public class CaseAMSInventory {
Public Case CaseAcct{get;set;}
    

      transient Public List<AMS_Inventory_Rollup__c> CI{get;set;}
             
                 public CaseAMSInventory(ApexPages.StandardController controller) {
                     CaseAcct=[select AccountID from case where ID = :ApexPages.currentPage().getParameters().get('id') ];
          CI=[select id,(select id,name,product_name__c,quantity__c, PFX_Account_Number__c from AMS_Inventory_Rollups__r where accountID__c =:CaseAcct ) from Case where ID=:ApexPages.currentPage().getParameters().get('id') ];
                     
         // System.Debug('CI: ' + CI.get(0));
        //System.Debug('Inventory: ' + CI.get(0).AMS_Inventory_rollups);
        
}

}


 
I have a custom object "Inventory", that has  a master detil relationship with the account object.
I need to be able to copy all of the related Inventory records to a custon object that has a master detail relationship to case, when the Account lookup is populated on the case reocrd.
Getting this error

System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, PfxTaxUpdateOppProposal: execution of AfterUpdate caused by: System.NullPointerException: Attempt to de-reference a null object Trigger.PfxTaxUpdateOppProposal: line 6, column 1: [] 
Stack Trace: Class.TestAxcessInsertTaxUpdateOpps.InsertOpp: line 20, column 1


On this test class

@isTest
Private Class TestPfxInsertTaxUpdateOpps{
static testMethod void InsertOpp(){

TaxUpdateYear__C TUY = new TaxUpdateYear__c(
name = 'UpdateYear',
year__c = '2018');
insert TUY;


Account A = new Account(
            Name = 'myAcct', 
            BillingStreet='25 Upland Drive',
            BillingPostalCode='94127',
            BillingCountry='United States',
            BillingCity='San Francisco',
            Pfx_Tax_Update_Counter__c = 0 );
        insert A;
        
        Account_x_reference__c xref = new account_x_reference__c(
name = '990026',
applicationid__c = '990026', 
application__c = 'AMS', ams_special_agreement__c = 'X', ams_consolidation_code__c = '028',
account__c = a.id);
insert xref;
        
        A.Pfx_Tax_Update_Counter__C = 1;
        a.Tax_Update_Account_Number__c = xref.id;
        
        update a;
        
        
   
        }
        }  

on this trigger

2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
trigger AxcessTaxUpdateOppProposal on Account (after update) {
    for (Account A:trigger.new){
    TaxUpdateYear__C TUY = TaxUpdateYear__c.getInstance('UpdateYear');
    String Year = TUY.year__c;
           Account oldAccount = Trigger.oldMap.get(A.Id);
        if(oldAccount.Axcess_Tax_Update_Counter__C <>  A.Axcess_Tax_Update_Counter__C){
          Opportunity O = new Opportunity(
          accountId = A.Id,
          name = a.name +' - '+Year+' Tax Update Order',
          amount = 150.00,
          StageName = '5. Time to Buy',
          ForecastCategoryName = 'High Probability',
          Forecast_Type__c = 'High(>90%)',
          Primary_contact_for_proposal__c = a.tax_update_contact__c,
          primary_contact_email__c = a.tax_update_contact_email__c,
          primary_contact_phone__C = a.tax_Update_Contact_phone__c,
          product_category__c = 'Small Firm Software',
          product_sub_category__c = 'Tax',
          type = 'New to Existing',
          RecordTypeId = '01231000001NWytAAG',
          closedate = system.Today(),
          OwnerId = UserInfo.getUserId()); 
          insert O;
            
            apttus_proposal__proposal__c P = new apttus_proposal__proposal__c(
            apttus_proposal__account__c = A.Id,
            apttus_proposal__proposal_name__c = O.name,
            apttus_proposal__approval_stage__c = 'Approved',
            apttus_proposal__opportunity__c = O.Id,
            quote_total__C = 150.00,
            RecordTypeId = '012i0000001EOtSAAW',
            apttus_QPConfig__PriceListId__c = 'a1fi0000000y6L4AAI',
            OwnerId = UserInfo.getUserId(),
            annual_start_date__c = system.Today()
          ,erp_account__c = A.Tax_Update_Account_number__c );            
            insert P;
            
            apttus_Config2__ProductConfiguration__c C = new apttus_Config2__ProductConfiguration__c (
            name = p.name,
            ownerId = UserInfo.getUserId(),
            Apttus_Config2__BusinessObjectId__c = P.Id,
            Apttus_Config2__BusinessObjectType__c = 'Proposal',
            Apttus_Config2__EffectivePriceListId__c = 'a1fi0000000y6L4AAI',
            Apttus_Config2__PriceListId__c = 'a1fi0000000y6L4AAI',
            Apttus_QPConfig__Proposald__c = P.Id,
            Apttus_Config2__Status__C = 'Finalized',
            Apttus_Config2__VersionNumber__c = 1,
            Proposal_ID__c = P.Id);
            Insert C;
            
             Apttus_Config2__LineItem__c CLI = new Apttus_Config2__LineItem__c(
                Apttus_Config2__ConfigurationId__c = C.Id,
                Apttus_Config2__ChargeType__c = 'One Time Fee',
                Apttus_Config2__BasePrice__c = 150.00,
                Apttus_Config2__BaseExtendedPrice__c = 150.00,
                Apttus_Config2__ExtendedPrice__c = 150.00,
                Apttus_Config2__IsPrimaryLine__c = true,
                Apttus_Config2__ItemSequence__c = 1,
                Apttus_Config2__LineNumber__c = 1,
                Apttus_Config2__ListPrice__c = 150.00,
                Apttus_Config2__LineStatus__c = 'New',
                Apttus_Config2__NetPrice__c = 150.00,
                Apttus_Config2__PriceListId__c = 'a1fi0000000y6L4AAI',
                apttus_config2__PriceListItemId__c = 'a1e0S0000007RYK',
                Apttus_Config2__PriceType__c = 'One Time',
                Apttus_Config2__ProductId__c = '01t0S000000krh9',
                Apttus_Config2__Quantity__c = 1,
                Apttus_Config2__SellingFrequency__c = 'Yearly',
                Apttus_Config2__SyncStatus__c = 'Synchronized',
                Apttus_Config2__PricingStatus__c = 'Complete',
                Apttus_Config2__PrimaryLineNumber__c = 1);
                Insert CLI; 
            
             
              apttus_proposal__proposal_line_item__c PLI = new apttus_proposal__proposal_line_item__c(
              apttus_proposal__proposal__c = p.Id,
                apttus_proposal__product__c = '01t0S000000krh9',
                apttus_qpconfig__quantity2__c = 1,
                apttus_qpconfig__linenumber__c = 1,
                apttus_qpconfig__itemsequence__c = 1,
                apttus_qpconfig__listprice__c = 150.00000,
                apttus_qpconfig__netprice__c = 150.00,
                apttus_qpconfig__linestatus__c = 'New',
                apttus_qpconfig__lineType__c = 'Product/Service',
                apttus_proposal__description__c = 'CCH AXCESS TAX UPDATE SEMINAR - MTS',
                apttus_qpconfig__PriceListItemId__c = 'a1e0S0000007RYK');
                insert PLI;
             Template_Line_item__C TLI = new Template_Line_Item__C(
                OwnerId = UserInfo.getUserId(),
                name = 'QLI-Record',
                ams_product_Category__c = 'Tax Professional & Client Services',
                Product__c = '01t0S000000krh9',
                Quote_Proposal__C = p.Id,
                display_ams_product_category__c = 'Tax Professional & Client Services',
                proposal_line_item__C = PLI.Id);
                
                insert TLI;
                
                  P.quote_total__c = 150.00;
                Update P;
                
                opportunitylineitem OLI = new opportunitylineitem(
                opportunityId = O.Id,
                product2Id = '01t0S000000krh9',
                Quantity = 1,
                TotalPrice = 150.00,
                Item_Number__C = '1',
                BasePrice__c = 150.00,
                PriceBookEntryId = '01u0S000001Lr93');
            
                
                insert OLI;   
               
                
   }
}
}


Trigger has 100% coverage in test.
Not sure why it is failing during deployment.
 
I have a trigger that inserts new line items into a custom object. One of the items I need to insert is the productID of a specific product.
How can I use [select id from product2 where productcode = 12345']  in an apex trigger?
trigger OutsourceOrderTotal on Apttus_Proposal__Proposal__c (after update) {    
    
  
       for(apttus_proposal__proposal__c p : trigger.new)
           if(p.os_offshore_1040_1041_dollars__c == null 
              && p.os_offshore_business_dollars__c == null 
              && p.os_offshore_charter_dollars__c == null 
              && p.os_onshore_1040_1041_dollars__c == null 
             && p.os_onshore_business_dollars__c == null
             &&p.os_onshore_charter_dollars__c == null)
           {
        p.os_order_total_trigger__c = 0;
    }
    else
         {             
            p.os_order_total_trigger__c = p.os_offshore_1040_1041_dollars__c +  p.os_offshore_business_dollars__c + p.os_offshore_charter_dollars__c
             + p.os_onshore_1040_1041_dollars__c + p.os_onshore_business_dollars__c + p.os_onshore_charter_dollars__c;
           }  
    
       
}
I have a process builder process that will create a new opportunity when a checkbox is set to true on the account.
I create the opportunity no problem, but I then want to also create a custom object related to the newly created opportunity as the next action in the process. is this possible?
I am getting "Too mant SOQL Queries" error in this chunk of code. it is in an Apex class, and I know they are running a SOQL query in a for loop (no no), but not sure how to correctly create and reference the map that they should be using.


if(opptyWonIds.size()<0){
            for(Opportunity wonOpp : [SELECT Id, Opportunity_Closed_Lost__c, Opportunity_Partial_Won__c, Opportunity_Closed_Won__c 
                                           FROM Opportunity WHERE Id IN: opptyWonIds]){
                if(wonOpp.Opportunity_Closed_Won__c != true){
                    wonOpp.Opportunity_Closed_Won__c = true;
                    if(wonOpp.Opportunity_Partial_Won__c == true || wonOpp.Opportunity_Closed_Lost__c == true){
                        wonOpp.Opportunity_Partial_Won__c = false;
                        wonOpp.Opportunity_Closed_Lost__c = false;
                   }
                    System.debug('*********************wonOpp: '+wonOpp);
                   opportunitiesToUpdate.add(wonOpp);
Here is my code.Link is blank.

Trigger SAPOrderComplete on Apttus_Proposal__Proposal__c (before update) {
for(apttus_proposal__proposal__c Proposal:trigger.new){
 apttus_proposal__proposal__c oldProposal = Trigger.oldMap.get(Proposal.Id);
  if((oldProposal.sap_order_complete__c == null || oldProposal.sap_order_complete__c == false) && proposal.sap_order_complete__c == true)
  {
  proposal.sap_order_processing_stage__c = 'Complete';
  proposal.sap_order_corrected__c = false;
  proposal.sap_order_rejected__c = false;
  if(proposal.sap_order_entered_date__c == null)
  {
  proposal.sap_order_entered_date__c = system.today();
  }
  Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
       
        String getProcessor = [select name from user where Id = :trigger.new[0].sap_order_processor__c].Name;
        String getAccount = [select name from account where id = :trigger.new[0].apttus_proposal__account__c].name;
        
        
        String[] Account = new String[] {getAccount};
        String[] Processor = new String[] {getProcessor};
        
        
        mail.TargetObjectId = (proposal.ownerId);
       
        mail.setSubject('Order completed for account: '+Account);
        mail.setHTMLBody('Order has been completed for proposal: <html><a href="'+URL.getSalesforceBaseUrl().toExternalForm() +'/'+Proposal.Id+'"></a></html>');
        mail.setSaveAsActivity(false);    
          
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
            
   }
}
}
Here is my code. Not sure why it is throwing this error. Without the display name setting, all works fine but appears as from the logged in user.

<apex:page standardController="Apttus_Proposal__Proposal__c">
<script type="text/javascript"> var __sfdcSessionId = '{!GETSESSIONID()}';  </script>
<script src="/soap/ajax/34.0/connection.js" type="text/javascript"></script> <script type="text/javascript">
window.onLoad = SendMail()
function SendMail()
{ try
{ sforce.connection.sessionId = "{!$Api.Session_ID}";
var target = "{!Apttus_Proposal__Proposal__c.opp_primary_contactId__c}";
 var message = new sforce.SingleEmailMessage();
message.replyTo = "noreply@wolterskluwer.com";
message.targetObjectId = target;
message.templateId = "00X0Z000001Fyuu";
message.saveAsActivity = false;
message.SenderDisplayName = "noreply@wolterskluwer.com";
var result = sforce.connection.sendEmail([message]);
if(result[0].success == 'true') { alert("Mail sent successfully"); }
else
{ alert("Error sending email."); } }catch(e) { alert("Error Occurred: \n\n" + (e.message||e)); } }
</script>
</apex:page>
I am running this script in a VF page. When executed, the url the link goes to has undefined at the end with an error that the URL no longerv exists.

<apex:page standardController="Opportunity">
<script src="/soap/ajax/10.0/connection.js"> </script > <script src="/soap/ajax/10.0/apex.js"> </script >
<script type="text/javascript">
window.onload=init()
function init()
{ var p = new sforce.SObject('Opportunity');
p.id = "{!Opportunity.Id}";
p.Tax_Renewal_SFS_Books_Complete__c = true;
result = sforce.connection.update([p]);
window.location.href = "https://wktaa.my.salesforce.com/"+p.Id; };
</script>
</apex:page>

It performs the field update, just errors out on the re-direct.
I have the same code running on another object and it works fine.
Any ideas?
public class CaseAddedProducts {
    public List<WrapperClass> listWrapper {get;set;}
    public Boolean allBool {get;set;}
    public  String caseID {get;set;}
    public CaseAddedProducts() {
    String accountID = System.currentPageReference().getParameters().get('accountID');
    caseID = System.currentPagereference().getParameters().get('caseID'); 
        listWrapper = new List<WrapperClass>();
        List<product> listprd = [SELECT Id, productcode, productname,productfamily,erp__c
        FROM product where isactive = true];
        if(listprd.size() > 0) {
            for(product prd : listprd) {
                listWrapper.add(new WrapperClass(prd));
            }
        }
    }
    
    public class WrapperClass {
        public Boolean checked {get;set;}
        public Product prd {get;set;}
        public WrapperClass(product prd) {
            this.prd = prd;
        }
    }
    
     public PageReference save()
    {
    PageReference caserec = new PageReference('/'+caseID);
    caserec.setredirect(true);
    return caserec;
    }
    
    public void add() {
        List<product> listprdforAdd = new List<product>();
        List<WrapperClass> listTempWrapper = new List<WrapperClass>();
        for(WrapperClass w : listWrapper) {
            if(w.checked) {
                listprdforAdd.add(w.prd);
            } 
        }
        //insert listWrapper into case_cancelled_inventory__c
        List<case_added_inventory__c> listCaseAddedInventory = new List<case_Added_inventory__c>();
   for(aproduct objprd : listprdforAdd){
    case_added_inventory__c objCaseAddedInventory = new case_added_inventory__c();     
    objCaseAddedInventory.Product_Code__c = objprd.productcode;
    objCaseAddedInventory.Product_Name__c = objprd.productname;
        objCaseAddedInventory.case__c = caseID;
    listCaseAddedInventory.add(objCaseAddedInventory);   
   }
   if(listCaseAddedInventory != null && listCaseAddedInventory.size() > 0)
    insert listAddedCaseInventory;
  //insert listWrapper into case_cancelled_inventory__c Ends

 
    }
    
    public void selectAll() {
        if(allBool) {
            for(WrapperClass w : listWrapper) {
                w.checked = true;
            }
        } else {
            for(WrapperClass w : listWrapper) {
                w.checked = false;
            }
        }
    }
}
Too many soql errors trigger msa data line 73

Getting error on this trigger fro one test class, but works fine from another test class.
trigger MSAData on Account (before insert,before update) {  
               Trigger

Map<String,String> MSALookup = new Map<String,String>();
  Set<String> AZipCode = new Set<String>();   
if(trigger.IsInsert){
 for(Account A:Trigger.new) {
    AZipCode.add(A.billingpostalcode);
 } 
 for(naics_code__c NA:
    [SELECT      zip_code__c, msa_code__c
     FROM        naics_code__c
     WHERE       zip_code__c IN :AZipCode]) {
    MSALookup.put(NA.zip_code__c,NA.msa_code__c);
  }
  for(Account A:Trigger.new) {
      if(MSALookup.containsKey(A.billingpostalcode)) {
      A.d_B_msa_code__c = MSALookup.get(A.billingpostalcode);
      }
  }    
    for(Account A:Trigger.new) {    
        AZipCode.add(A.billingpostalcode);
    }    
    for(naics_code__c NA:
    [SELECT      zip_code__c, msa_name__c
     FROM        naics_code__c
     WHERE       zip_code__c IN :AZipCode]) {
    MSALookup.put(NA.zip_code__c,NA.msa_name__c);
  }
  for(Account A:Trigger.new) {
      if(MSALookup.containsKey(A.billingpostalcode)) {
      A.d_B_msa_description__c = MSALookup.get(A.billingpostalcode);
      }
  }
}
if(trigger.isUpdate){    
    for(Account acct:trigger.new){
        account oldAcct= Trigger.oldmap.get(Acct.Id);
    if (oldacct.BillingPostalCode<>Acct.BillingPostalCode){
        AZipCode.add(acct.billingpostalcode);
        } 
    }
    for(naics_code__c NA:
    [SELECT      zip_code__c, msa_name__c
     FROM        naics_code__c
     WHERE       zip_code__c IN :AZipCode]) {
    MSALookup.put(NA.zip_code__c,NA.msa_name__c);
  }  
  for(Account A:Trigger.new) {
      if(MSALookup.containsKey(A.billingpostalcode)) {
      A.d_B_msa_description__c = MSALookup.get(A.billingpostalcode);
      }
  }
    for(Account A:Trigger.new) {
            AZipCode.add(A.billingpostalcode);  
 } 
 for(naics_code__c NA:
    [SELECT      zip_code__c, msa_code__c
     FROM        naics_code__c
     WHERE       zip_code__c IN :AZipCode]) {
    MSALookup.put(NA.zip_code__c,NA.msa_code__c);
  }
  for(Account A:Trigger.new) {
      if(MSALookup.containsKey(A.billingpostalcode)) {
      A.d_B_msa_code__c = MSALookup.get(A.billingpostalcode);
      }
  }
}
}

Test Class
@isTest 
private class TestTaskEventRollup_RecordType {

    static testMethod void InsertTask() {

Account A = new Account(
            Name = 'myAcct', 
            BillingStreet='25 Upland Drive',
            BillingPostalCode='94127',
            BillingCountry='United States',
            BillingCity='San Francisco',
            recordtypeid = '012i0000000Ou0CAAS',
            software_owner__C = '005i0000001gISQAA2' );
        insert A;
       

Campaign Cam = new Campaign(
        name = '18--support-phone inbound-torrance',
        type = 'Direct mail',
        isactive = true);
        insert Cam;
        
 Contact c = new Contact(
        firstname = 'Jim', lastname = 'Montgomery');
        Insert c;

 Opportunity O = new Opportunity(
        Name = 'TestOpp',
        accountId = A.Id,
        type = 'New to Existing',
        Closedate = Date.today().addYears(1),
        stagename = '1. Gain Access',
        product_category__c = 'Med/Large Software',
        Amount = 1.00,
        product_Sub_Category__c = 'Tax');
        insert O;
        
       Task tsk = New Task(
Type = 'Email',
WhatId = A.Id,

Subject = 'Call'
);
insert tsk;

Task tsk2 = New Task(
Type = 'Email',
whatId = A.Id,
Subject = 'Call'
);
insert tsk2;

Task tsk3 = New Task(
Type = 'Email',
whatId = A.Id,
Subject = 'Call'
);
insert tsk3;
Event Evt = New Event(
OwnerId = '005i0000001gISQAA2',
subject = 'Demonstration',
event_type__c = 'Demo - Professional',
whatId = A.Id,
no_sa_needed__c = true,
startdatetime = datetime.newInstance(2018, 9, 15, 12, 30, 0),
enddatetime = datetime.newInstance(2018, 9, 15, 12, 35, 0));
insert Evt;

Event Evt1 = New Event(
OwnerId = '005i0000001gISQAA2',
subject = 'Demonstration',
event_type__c = 'Conference Call',
whatId = A.Id,
no_sa_needed__c = true,
startdatetime = datetime.newInstance(2018, 9, 15, 12, 30, 0),
enddatetime = datetime.newInstance(2018, 9, 15, 12, 35, 0));
insert Evt1;

Event Evt2 = New Event(
OwnerId = '005i0000001gISQAA2',
subject = 'Demonstration',
event_type__c = 'In_Person Meeting',
whatId = A.Id,
no_sa_needed__c = true,
startdatetime = datetime.newInstance(2018, 9, 15, 12, 30, 0),
enddatetime = datetime.newInstance(2018, 9, 15, 12, 35, 0));
insert Evt2;
}
}
I have a trigger on task that will update the task with the accounts record type on insertion.
I also need to do this on an update, but get the "maximum Trigger Depth" error when adding before update to the trigger.

trigger TaskAccountType on Task (after insert) {
    Task T = [select Id,WhatId,subject from task where Id = :trigger.new[0].Id];
    if(trigger.new[0].Id!=null){
    string WhatId = t.WhatId;
    
    if(t.WhatId!=NULL){
   if(WhatId.startswith('0')){
    Account a = [select id,recordtypeid from Account where id =: trigger.new[0].AccountId];
if(trigger.new[0].AccountId!=null){  
if(a.recordtypeid == '012i0000000Ou0CAAS'){
        t.Account_record_Type__c ='Customer Account'; 
        update T;       
        }
        else
        if(a.recordtypeid == '012i0000000Ou0EAAS'){
        t.Account_record_Type__c = 'Prospect Account';  
        update T;      
        }
        else
        if(a.recordtypeid == '012i0000000Ou0DAAS'){
        t.Account_record_Type__c = 'Partner Account';  
        update T;      
        }
}
}
}
}
}
Here is my trigger and test class. I can create an account with the exact same properties as they account in the test class, and it works fine. But thr test class fails with this error.
Error:
System.DmlException: Update failed. First exception on row 0 with id 0010x00000FTfC0AAL; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, RCLeadAutoCreateFromAccount: execution of AfterUpdate

caused by: System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_EXECUTE_FLOW_TRIGGER, The record couldn’t be saved because it failed to trigger a flow. A flow trigger failed to execute the flow with version ID 3010x0000000W9o. Flow error messages: <b>An unhandled fault has occurred in this flow</b><br>An unhandled fault has occurred while processing the flow. Please contact your system administrator for more information. Contact your administrator for help.: []

Trigger.RCLeadAutoCreateFromAccount: line 24, column 1: []
Stack TraceClass.TestRCLeadAutoCreate.insertAccount: line 27, column 1


Trigger:
trigger RCLeadAutoCreateFromAccount on Account (after update) {
    for (Account A:Trigger.New){
    String Name = UserInfo.getName();
         Account oldAccount = Trigger.oldMap.get(A.Id);
        if(oldAccount.RC_Lead_TimeStamp__c != A.RC_Lead_TimeStamp__c){
        Campaign C = [select id from campaign where name = '18--support-phone inbound-torrance'];
              Lead L = new Lead(
                company = A.name,
                status = 'Not Started',
                lastname = 'RC Lead',
                rating = 'Hot',
                market_segment__c = A.Market_Segment__c,
                market_sub_segment__c = A.Market_Sub_Segment__c,
                street = a.billingstreet,
                city = a.billingcity,
                state = a.billingstate,
                PostalCode = a.BillingPostalCode,
                named_account_type__c = a.Named_Account_Type__c,
                related_account__c = a.Id,
                description = a.rc_lead_comments__c,
                rc_lead_product_interest__c = a.rc_lead_product_interest_MS__c);
            insert L;
            if(A.Named_Account_Type__c == 'Small Firm Tax Customer'){
                L.small_market_N2E__c = True;
                update L;
            }
            campaignmember CM = new campaignmember(
                campaignID = C.Id, 
                comments__c = a.rc_lead_comments__c,             
                leadID = L.ID
                    );
                insert cm;
                             
        }
        
    
    }
}

Test Class:
@isTest 
private class TestRCLeadAutoCreate {

    static testMethod void insertAccount() {
    string name = 'Jim Montgomery';
   Account A = new Account(
            Name = 'myAcct', 
            BillingStreet='25 Upland Drive',
            BillingPostalCode='94127',
            BillingCountry='United States',
            BillingCity='San Francisco',
            market_segment__c = 'Accounting Firms',
            market_sub_segment__c = 'Sole Proprietor',
            billingstate = 'CA',
            named_account_type__c = 'Strategic',
            rc_lead_comments__c = 'Test',
            rc_lead_product_interest_ms__c = 'Pfx Tax'
            );
        insert A;
        Campaign Cam = new Campaign(
        name = '18--support-phone inbound-torrance',
        type = 'Direct mail',
        isactive = true);
        insert Cam;
        
        a.rc_lead_timestamp__c = system.now();
        update a;
        }
        }
Not sure where this is erroring out.

trigger MSAData on Account (before insert,before update) { 
    for (account Acc:trigger.new){       
               
Map<String,String> MSALookup = new Map<String,String>();
  Set<String> AZipCode = new Set<String>();  
  
        
if(trigger.IsInsert){
 for(Account A:Trigger.new) {
    AZipCode.add(A.billingpostalcode);
  for(naics_code__c NA:
    [SELECT      zip_code__c, msa_code__c
     FROM        naics_code__c
     WHERE       zip_code__c IN :AZipCode]) {

    MSALookup.put(NA.zip_code__c,NA.msa_code__c);
  }
 }

  for(Account A:Trigger.new) {
      if(MSALookup.containsKey(A.billingpostalcode)) {
      A.d_B_msa_code__c = MSALookup.get(A.billingpostalcode);
      }
  }
    
    for(Account A:Trigger.new) {    
    AZipCode.add(A.billingpostalcode);
        
 for(naics_code__c NA:
    [SELECT      zip_code__c, msa_name__c
     FROM        naics_code__c
     WHERE       zip_code__c IN :AZipCode]) {

    MSALookup.put(NA.zip_code__c,NA.msa_name__c);
  }
 }

  for(Account A:Trigger.new) {
      if(MSALookup.containsKey(A.billingpostalcode)) {
      A.d_B_msa_description__c = MSALookup.get(A.billingpostalcode);
      }
  }
}
else                    

    
if(trigger.isUpdate){    

    for(Account acct:trigger.new){
        account oldAcct= Trigger.oldmap.get(Acct.Id);
    if (oldacct.BillingPostalCode<>Acct.BillingPostalCode){
    
    for(Account A:Trigger.new) {
        
       
           
    AZipCode.add(A.billingpostalcode);
       
 for(naics_code__c NA:
    [SELECT      zip_code__c, msa_name__c
     FROM        naics_code__c
     WHERE       zip_code__c IN :AZipCode]) {

    MSALookup.put(NA.zip_code__c,NA.msa_name__c);
  }
    }
    
  for(Account A:Trigger.new) {
      if(MSALookup.containsKey(A.billingpostalcode)) {
      A.d_B_msa_description__c = MSALookup.get(A.billingpostalcode);
      }
  }
    for(Account A:Trigger.new) {
        
    AZipCode.add(A.billingpostalcode);
  for(naics_code__c NA:
    [SELECT      zip_code__c, msa_code__c
     FROM        naics_code__c
     WHERE       zip_code__c IN :AZipCode]) {

    MSALookup.put(NA.zip_code__c,NA.msa_code__c);
  }
 }

  for(Account A:Trigger.new) {
      if(MSALookup.containsKey(A.billingpostalcode)) {
      A.d_B_msa_code__c = MSALookup.get(A.billingpostalcode);
      }
  }
}
}
}
}
}
I am getting error Invalid Type: listAIRforAdd line 39
Code:
public class CaseInventory {

    public List<WrapperClass> listWrapper {get;set;}
    public Boolean allBool {get;set;}
    
    public CaseInventory() {
    String accountID = System.currentPageReference().getParameters().get('accountID');
    String caseID = System.currentPagereference().getParameters().get('caseID'); 
        listWrapper = new List<WrapperClass>();
        List<ams_inventory_rollup__c> listAIR = [SELECT Id, Name, product_name__c,quantity__c,pfx_account_number__c 
        FROM ams_inventory_rollup__c where AccountId__c = :accountId];
        if(listAIR.size() > 0) {
            for(ams_inventory_rollup__c air : listAIR) {
                listWrapper.add(new WrapperClass(air));
            }
        }
    }
    
    public class WrapperClass {
        public Boolean checked {get;set;}
        public ams_inventory_rollup__c air {get;set;}
        public WrapperClass(ams_inventory_rollup__c air) {
            this.air = air;
        }
    }
    
    public void add() {
        List<ams_inventory_rollup__c> listAIRforAdd = new List<ams_inventory_rollup__c>();
        List<WrapperClass> listTempWrapper = new List<WrapperClass>();
        for(WrapperClass w : listWrapper) {
            if(w.checked) {
                listAIRforAdd.add(w.air);
            } 
        }
        
    }
  List<Case_Inventories__c> CaseINVs = new List<case_Inventories__c>();
    
    for(listAIRforAdd wrAIR:listWrapper){
    case_inventories__c CI = new case_inventories__c();
    ci.product_code__c = wrAIR.name;
    ci.product_name__c = wrAIR.product_name__c;
    ci.quantity__c = wrAIR.quantity;
    CaseINVs.add(wrAIR);
    }
    Insert CaseINVs;
    
    public void selectAll() {
        if(allBool) {
            for(WrapperClass w : listWrapper) {
                w.checked = true;
            }
        } else {
            for(WrapperClass w : listWrapper) {
                w.checked = false;
            }
        }
    }
}
 
I need help with a formula for a validation rule. Users should be required to fill in 9 fields before leaving the prove stage. What I have so far is below. It is working as far as all the fields being required....however when I fill in all the fields I still can't save and still get the error. What am I missing? 

Also please not that this is only required for certain opp types which I have included as well.

AND(
    CASE(
        Opportunity_Type__c,
        "NET NEW",      1,
        "Cross-Sell",   1,
        "Up-Sell",      1,
        "Add-on",       1,
        0
    ) = 1,

    ISCHANGED(StageName),
    ISPICKVAL(PRIORVALUE(StageName), "3-Prove"),

    OR(
        ISBLANK(Metrics__c),
        ISBLANK(Decision_Criteria__c),
        ISBLANK (Champion_1__c), 
        ISBLANK (Champion_2__c),
        MEDDPICC_Completed__c = False, 
        Budget__c = False,
        Tech_Profile_Completed__c = False,
        Technical_Win_Achieved__c =False,
        ISBLANK(Competitor__c)
 ))

 
Hi,
The WFR below works everytime the field PV Projet Status is change to either "Given to Foreperson" or "Superintendent" from a blank field OR if the field equals something else aside from Given to Foreperson or Superintendent. However, I also want it to fire everytime it is changed from Given to Foreperson TO Superintendent, or Superintendent TO Given to Foreperson. 

OR ( 
ISPICKVAL(PV_Project_Status__c, 'Given to Foreperson'),
ISPICKVAL(PV_Project_Status__c, 'Superintendent')
)

For it to work, I had to split them into two separate WFR (see below), which is ok but I would like them to be in one WFR.
WFR 1: ISPICKVAL(PV_Project_Status__c, 'Given to Foreperson')
WFR 2: ISPICKVAL(PV_Project_Status__c, 'Superintendent')

Thanks,
Marge
Getting this error

System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, PfxTaxUpdateOppProposal: execution of AfterUpdate caused by: System.NullPointerException: Attempt to de-reference a null object Trigger.PfxTaxUpdateOppProposal: line 6, column 1: [] 
Stack Trace: Class.TestAxcessInsertTaxUpdateOpps.InsertOpp: line 20, column 1


On this test class

@isTest
Private Class TestPfxInsertTaxUpdateOpps{
static testMethod void InsertOpp(){

TaxUpdateYear__C TUY = new TaxUpdateYear__c(
name = 'UpdateYear',
year__c = '2018');
insert TUY;


Account A = new Account(
            Name = 'myAcct', 
            BillingStreet='25 Upland Drive',
            BillingPostalCode='94127',
            BillingCountry='United States',
            BillingCity='San Francisco',
            Pfx_Tax_Update_Counter__c = 0 );
        insert A;
        
        Account_x_reference__c xref = new account_x_reference__c(
name = '990026',
applicationid__c = '990026', 
application__c = 'AMS', ams_special_agreement__c = 'X', ams_consolidation_code__c = '028',
account__c = a.id);
insert xref;
        
        A.Pfx_Tax_Update_Counter__C = 1;
        a.Tax_Update_Account_Number__c = xref.id;
        
        update a;
        
        
   
        }
        }  

on this trigger

2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
trigger AxcessTaxUpdateOppProposal on Account (after update) {
    for (Account A:trigger.new){
    TaxUpdateYear__C TUY = TaxUpdateYear__c.getInstance('UpdateYear');
    String Year = TUY.year__c;
           Account oldAccount = Trigger.oldMap.get(A.Id);
        if(oldAccount.Axcess_Tax_Update_Counter__C <>  A.Axcess_Tax_Update_Counter__C){
          Opportunity O = new Opportunity(
          accountId = A.Id,
          name = a.name +' - '+Year+' Tax Update Order',
          amount = 150.00,
          StageName = '5. Time to Buy',
          ForecastCategoryName = 'High Probability',
          Forecast_Type__c = 'High(>90%)',
          Primary_contact_for_proposal__c = a.tax_update_contact__c,
          primary_contact_email__c = a.tax_update_contact_email__c,
          primary_contact_phone__C = a.tax_Update_Contact_phone__c,
          product_category__c = 'Small Firm Software',
          product_sub_category__c = 'Tax',
          type = 'New to Existing',
          RecordTypeId = '01231000001NWytAAG',
          closedate = system.Today(),
          OwnerId = UserInfo.getUserId()); 
          insert O;
            
            apttus_proposal__proposal__c P = new apttus_proposal__proposal__c(
            apttus_proposal__account__c = A.Id,
            apttus_proposal__proposal_name__c = O.name,
            apttus_proposal__approval_stage__c = 'Approved',
            apttus_proposal__opportunity__c = O.Id,
            quote_total__C = 150.00,
            RecordTypeId = '012i0000001EOtSAAW',
            apttus_QPConfig__PriceListId__c = 'a1fi0000000y6L4AAI',
            OwnerId = UserInfo.getUserId(),
            annual_start_date__c = system.Today()
          ,erp_account__c = A.Tax_Update_Account_number__c );            
            insert P;
            
            apttus_Config2__ProductConfiguration__c C = new apttus_Config2__ProductConfiguration__c (
            name = p.name,
            ownerId = UserInfo.getUserId(),
            Apttus_Config2__BusinessObjectId__c = P.Id,
            Apttus_Config2__BusinessObjectType__c = 'Proposal',
            Apttus_Config2__EffectivePriceListId__c = 'a1fi0000000y6L4AAI',
            Apttus_Config2__PriceListId__c = 'a1fi0000000y6L4AAI',
            Apttus_QPConfig__Proposald__c = P.Id,
            Apttus_Config2__Status__C = 'Finalized',
            Apttus_Config2__VersionNumber__c = 1,
            Proposal_ID__c = P.Id);
            Insert C;
            
             Apttus_Config2__LineItem__c CLI = new Apttus_Config2__LineItem__c(
                Apttus_Config2__ConfigurationId__c = C.Id,
                Apttus_Config2__ChargeType__c = 'One Time Fee',
                Apttus_Config2__BasePrice__c = 150.00,
                Apttus_Config2__BaseExtendedPrice__c = 150.00,
                Apttus_Config2__ExtendedPrice__c = 150.00,
                Apttus_Config2__IsPrimaryLine__c = true,
                Apttus_Config2__ItemSequence__c = 1,
                Apttus_Config2__LineNumber__c = 1,
                Apttus_Config2__ListPrice__c = 150.00,
                Apttus_Config2__LineStatus__c = 'New',
                Apttus_Config2__NetPrice__c = 150.00,
                Apttus_Config2__PriceListId__c = 'a1fi0000000y6L4AAI',
                apttus_config2__PriceListItemId__c = 'a1e0S0000007RYK',
                Apttus_Config2__PriceType__c = 'One Time',
                Apttus_Config2__ProductId__c = '01t0S000000krh9',
                Apttus_Config2__Quantity__c = 1,
                Apttus_Config2__SellingFrequency__c = 'Yearly',
                Apttus_Config2__SyncStatus__c = 'Synchronized',
                Apttus_Config2__PricingStatus__c = 'Complete',
                Apttus_Config2__PrimaryLineNumber__c = 1);
                Insert CLI; 
            
             
              apttus_proposal__proposal_line_item__c PLI = new apttus_proposal__proposal_line_item__c(
              apttus_proposal__proposal__c = p.Id,
                apttus_proposal__product__c = '01t0S000000krh9',
                apttus_qpconfig__quantity2__c = 1,
                apttus_qpconfig__linenumber__c = 1,
                apttus_qpconfig__itemsequence__c = 1,
                apttus_qpconfig__listprice__c = 150.00000,
                apttus_qpconfig__netprice__c = 150.00,
                apttus_qpconfig__linestatus__c = 'New',
                apttus_qpconfig__lineType__c = 'Product/Service',
                apttus_proposal__description__c = 'CCH AXCESS TAX UPDATE SEMINAR - MTS',
                apttus_qpconfig__PriceListItemId__c = 'a1e0S0000007RYK');
                insert PLI;
             Template_Line_item__C TLI = new Template_Line_Item__C(
                OwnerId = UserInfo.getUserId(),
                name = 'QLI-Record',
                ams_product_Category__c = 'Tax Professional & Client Services',
                Product__c = '01t0S000000krh9',
                Quote_Proposal__C = p.Id,
                display_ams_product_category__c = 'Tax Professional & Client Services',
                proposal_line_item__C = PLI.Id);
                
                insert TLI;
                
                  P.quote_total__c = 150.00;
                Update P;
                
                opportunitylineitem OLI = new opportunitylineitem(
                opportunityId = O.Id,
                product2Id = '01t0S000000krh9',
                Quantity = 1,
                TotalPrice = 150.00,
                Item_Number__C = '1',
                BasePrice__c = 150.00,
                PriceBookEntryId = '01u0S000001Lr93');
            
                
                insert OLI;   
               
                
   }
}
}


Trigger has 100% coverage in test.
Not sure why it is failing during deployment.
 
I have a trigger that inserts new line items into a custom object. One of the items I need to insert is the productID of a specific product.
How can I use [select id from product2 where productcode = 12345']  in an apex trigger?
trigger OutsourceOrderTotal on Apttus_Proposal__Proposal__c (after update) {    
    
  
       for(apttus_proposal__proposal__c p : trigger.new)
           if(p.os_offshore_1040_1041_dollars__c == null 
              && p.os_offshore_business_dollars__c == null 
              && p.os_offshore_charter_dollars__c == null 
              && p.os_onshore_1040_1041_dollars__c == null 
             && p.os_onshore_business_dollars__c == null
             &&p.os_onshore_charter_dollars__c == null)
           {
        p.os_order_total_trigger__c = 0;
    }
    else
         {             
            p.os_order_total_trigger__c = p.os_offshore_1040_1041_dollars__c +  p.os_offshore_business_dollars__c + p.os_offshore_charter_dollars__c
             + p.os_onshore_1040_1041_dollars__c + p.os_onshore_business_dollars__c + p.os_onshore_charter_dollars__c;
           }  
    
       
}
I am getting "Too mant SOQL Queries" error in this chunk of code. it is in an Apex class, and I know they are running a SOQL query in a for loop (no no), but not sure how to correctly create and reference the map that they should be using.


if(opptyWonIds.size()<0){
            for(Opportunity wonOpp : [SELECT Id, Opportunity_Closed_Lost__c, Opportunity_Partial_Won__c, Opportunity_Closed_Won__c 
                                           FROM Opportunity WHERE Id IN: opptyWonIds]){
                if(wonOpp.Opportunity_Closed_Won__c != true){
                    wonOpp.Opportunity_Closed_Won__c = true;
                    if(wonOpp.Opportunity_Partial_Won__c == true || wonOpp.Opportunity_Closed_Lost__c == true){
                        wonOpp.Opportunity_Partial_Won__c = false;
                        wonOpp.Opportunity_Closed_Lost__c = false;
                   }
                    System.debug('*********************wonOpp: '+wonOpp);
                   opportunitiesToUpdate.add(wonOpp);
Trying to assign extended_maintenance_months__c as the variable months in the definition of addMonths.

trigger SoftwareAnnualEndDates on Apttus_Proposal__Proposal__c (After update) {

    List<apttus_proposal__proposal_line_item__c> lstToUpdate = new List<apttus_proposal__proposal_line_item__c>();

    for(apttus_proposal__proposal_line_item__c obj :[select maintenance_end_date__c, proposal_end_date__c,extended_maintenance_months__c from apttus_proposal__proposal_line_item__c where extended_maintenance_months__c >0 and apttus_proposal__proposal__c != null and apttus_proposal__proposal__c in : trigger.new])
       
    {         
        obj.maintenance_end_date__c = proposal_end_date__c.addMonths(Months);

        lstToUpdate.add(obj);
   }

    if(!lstToUpdate.isEmpty())

        update lstToUpdate;

}
Code.
Getting sent to the login page on re-direct.

<apex:page standardController="Apttus_Proposal__Proposal__c"> <script src="/soap/ajax/10.0/connection.js"> </script > <script src="/soap/ajax/10.0/apex.js"> </script > <apex:iframe src="{!URLFOR($Resource.SAP_Order_Checklist)}" id="theIframe"/> <script type="text/javascript"> window.onload=init() function init() { var p = new sforce.SObject('Apttus_Proposal__Proposal__c'); p.Id = "{!Apttus_Proposal__Proposal__c.Id}"; p.sap_checklist_accessed__c = true; result = sforce.connection.update([p]); location.href="https://wktaatest--taatest.cs54.my.salesforce.com/"+p.Id }; </script> </apex:page>