function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
JN22JN22 

OpportunityLineItem Trigger To Update Checkbox

Hello,

 

I have created the trigger below.  It saves fine and runs without errors, but it does not do anything.  It's meant to trigger when an Opportunity Product is added, edited, or deleted.  It looks at some criteria on the Product (i.e., Product_Group__c, Product_Family__c, and ProductCode) and then checks or unchecks 3 custom fields on the associated Opportunity (Product__c, Service__c, 3rdParty__c) based on whether or not products have been chosen that meet the criteria.  However, as I mentioned, the trigger does not seem to do anything when the products are added or edited.  Is there something I am missing or something I did not do correctly?  Thanks for any help!

 

trigger FieldUpdates1 on OpportunityLineItem (before insert, before update, before delete)
{
//Update Opportunity section fields based on product(s) chosen

Map<Id,Opportunity> Opp1 = new Map<Id,Opportunity>();
set<Id> Ids = new Set <Id>();

FOR(OpportunityLineItem OppLine1 :trigger.new) {
Ids.add(OppLine1.OpportunityId);
}

Map<id,Opportunity> Opp2 = New Map<id,Opportunity>([SELECT Id, Product__c,Service__c,3rdParty__c
FROM Opportunity
WHERE Id IN :Ids]);

for(OpportunityLineItem OppLine2 : trigger.new)
{
Opportunity Opp2a = Opp2.get(OppLine2.OpportunityId);

if((OppLine2.Product_Group__c == 'Product') && (OppLine2.Product_Family__c == 'Group 1')){
Opp2a.Product__c = true;
}
else {
Opp2a.Product__c = FALSE;
}

if((OppLine2.Product_Group__c == 'Service') && (OppLine2.PricebookEntry.Product2.ProductCode == 'GROUP_2')){
Opp2a.Service__c = TRUE;
}
else {
Opp2a.Service__c = FALSE;
}

if((OppLine2.Product_Group__c == '3rdParty') && (OppLine2.PricebookEntry.Product2.ProductCode == 'GROUP_2')){
Opp2a.3rdParty__c = TRUE;
}
else {
Opp2a.3rdParty__c = FALSE;
}

Opp1.put(Opp2a.id,Opp2a);
}

Update Opp1.Values();
}

Parth_SevakParth_Sevak
Here you are using update. now update only works when trigger is fired due to update operation.
change with upsert opp1.values(); also try if this not works then upsert opp2.values();
so trigger can fire on before insert operation also.
And also try to make code as much simpler and sort.
hope this will help you.
JN22JN22

Thanks for the response.  Unfortunately, neither of those changes worked to update the fields on the Opportunity.  Do you have any other ideas?  Thanks,

Parth_SevakParth_Sevak
can you try this ?

trigger FieldUpdates1 on OpportunityLineItem (before insert, before update, before delete)
{
List<OpportunityLineItem> updatedOLItems = new List<OpportunityLineItem>();

for(OpportunityLineItem OppLine2 : trigger.new)
{

if((OppLine2.Product_Group__c == 'Product') && (OppLine2.Product_Family__c == 'Group 1')){
OppLine2.Product__c = true;
}
else {
OppLine2.Product__c = FALSE;
}

if((OppLine2.Product_Group__c == 'Service') && (OppLine2.PricebookEntry.Product2.ProductCode == 'GROUP_2')){
OppLine2.Service__c = TRUE;
}
else {
OppLine2.Service__c = FALSE;
}

if((OppLine2.Product_Group__c == '3rdParty') && (OppLine2.PricebookEntry.Product2.ProductCode == 'GROUP_2')){
OppLine2.3rdParty__c = TRUE;
}
else {
OppLine2.3rdParty__c = FALSE;
}

updatedOLItems.add(OppLine2);

}
upsert updatedOLItems;
}
all the best...
Vinit_KumarVinit_Kumar

Jn,

 

The code looks good,the way I would approach here is that I will put some debug statements in the Trigger to check the values and then check in debug logs as what is getting printed.I mean to say I will check the value before and after update and to make sue whether the record is  being updated or not.

JN22JN22

parth2322, those changes don't work because the checkbox fields are at the Opportunity level, not on OpportunityLineItems which is where you have them in your code

JN22JN22

Vinit,

 

Thanks.  I'm nt very familiar with how to use system.debug statements.  Can you give me an example of where I would put them in the code to see the values?  Thanks.

Vinit_KumarVinit_Kumar

JN,

 

Please try the below code and see what you find in debug logs :-

 

trigger FieldUpdates1 on OpportunityLineItem (before insert, before update, before delete)
{
//Update Opportunity section fields based on product(s) chosen
Map<Id,Opportunity> Opp1 = new Map<Id,Opportunity>();
set<Id> Ids = new Set <Id>();
FOR(OpportunityLineItem OppLine1 :trigger.new) {
Ids.add(OppLine1.OpportunityId);
}

Map<id,Opportunity> Opp2 = New Map<id,Opportunity>([SELECT Id, Product__c,Service__c,3rdParty__c
FROM Opportunity
WHERE Id IN :Ids]);
for(OpportunityLineItem OppLine2 : trigger.new)
{
Opportunity Opp2a = Opp2.get(OppLine2.OpportunityId);

if((OppLine2.Product_Group__c == 'Product') && (OppLine2.Product_Family__c == 'Group 1')){
Opp2a.Product__c = true;
system.debug('*****1***' +Opp2a);
}
else {
Opp2a.Product__c = FALSE;
system.debug('*****2***' + Opp2a);
}

if((OppLine2.Product_Group__c == 'Service') && (OppLine2.PricebookEntry.Product2.ProductCode == 'GROUP_2')){
Opp2a.Service__c = TRUE;
system.debug('*****3***' + Opp2a);
}
else {
Opp2a.Service__c = FALSE;
system.debug('*****4***' + Opp2a);
}

if((OppLine2.Product_Group__c == '3rdParty') && (OppLine2.PricebookEntry.Product2.ProductCode == 'GROUP_2')){
Opp2a.3rdParty__c = TRUE;
system.debug('*****5***' + Opp2a);
}
else {
Opp2a.3rdParty__c = FALSE;
system.debug('*****6***' + Opp2a);
}

Opp1.put(Opp2a.id,Opp2a);
}
Update Opp1.Values();
system.debug('##########' + Opp1.Values());
}

JN22JN22

Hi Vinit,

 

Thanks.  I input those statements and all of the False ones are showing in the debug log but none of the true ones show up.  Any idea why that may be?

Vinit_KumarVinit_Kumar

Hi JN,

 

Can you post the debug logs here,I want to take a look.I want to see which if condition is being executed here.

JN22JN22

Hi Vinit,

 

The debug log is below. Thanks,

 

27.0 APEX_CODE,DEBUG;APEX_PROFILING,INFO;CALLOUT,INFO;DB,INFO;SYSTEM,DEBUG;VALIDATION,INFO;VISUALFORCE,INFO;WORKFLOW,INFO
14:53:00.055 (55900000)|EXECUTION_STARTED
14:53:00.055 (55941000)|CODE_UNIT_STARTED|[EXTERNAL]|Validation:OpportunityLineItem:00kS0000005SD0J
14:53:00.055 (55953000)|VALIDATION_RULE|03d700000000VyG|Discount_for_Waived_WO
14:53:00.056 (56156000)|VALIDATION_FORMULA|and( Opportunity.Work_Order_Waived__c = TRUE,
not(isblank( Discount_Amount__c )))|Opportunity.Work_Order_Waived__c=0 , Discount_Amount__c=null
14:53:00.056 (56165000)|VALIDATION_PASS
14:53:00.056 (56168000)|CODE_UNIT_FINISHED|Validation:OpportunityLineItem:00kS0000005SD0J
14:53:00.056 (56176000)|EXECUTION_FINISHED
14:53:00.105 (105707000)|EXECUTION_STARTED
14:53:00.105 (105719000)|CODE_UNIT_STARTED|[EXTERNAL]|01qS00000004kj8|FieldUpdates1 on OpportunityLineItem trigger event AfterUpdate for [00kS0000005SD0J]
14:53:00.106 (106857000)|SYSTEM_CONSTRUCTOR_ENTRY|[6]|<init>(Integer)
14:53:00.106 (106897000)|SYSTEM_CONSTRUCTOR_EXIT|[6]|<init>(Integer)
14:53:00.107 (107042000)|SYSTEM_METHOD_ENTRY|[8]|LIST<OpportunityLineItem>.iterator()
14:53:00.107 (107387000)|SYSTEM_METHOD_EXIT|[8]|LIST<OpportunityLineItem>.iterator()
14:53:00.107 (107414000)|SYSTEM_METHOD_ENTRY|[8]|system.ListIterator.hasNext()
14:53:00.107 (107443000)|SYSTEM_METHOD_EXIT|[8]|system.ListIterator.hasNext()
14:53:00.107 (107544000)|SYSTEM_METHOD_ENTRY|[9]|SET<Id>.add(Object)
14:53:00.107 (107578000)|SYSTEM_METHOD_EXIT|[9]|SET<Id>.add(Object)
14:53:00.107 (107588000)|SYSTEM_METHOD_ENTRY|[8]|system.ListIterator.hasNext()
14:53:00.107 (107599000)|SYSTEM_METHOD_EXIT|[8]|system.ListIterator.hasNext()
14:53:00.107 (107919000)|SOQL_EXECUTE_BEGIN|[12]|Aggregations:0|select Id, Product__c, Service__c, 3rdParty__c from Opportunity where Id = :tmpVar1
14:53:00.127 (127554000)|SOQL_EXECUTE_END|[12]|Rows:1
14:53:00.127 (127750000)|SYSTEM_METHOD_ENTRY|[17]|LIST<OpportunityLineItem>.iterator()
14:53:00.127 (127795000)|SYSTEM_METHOD_EXIT|[17]|LIST<OpportunityLineItem>.iterator()
14:53:00.127 (127808000)|SYSTEM_METHOD_ENTRY|[17]|system.ListIterator.hasNext()
14:53:00.127 (127822000)|SYSTEM_METHOD_EXIT|[17]|system.ListIterator.hasNext()
14:53:00.127 (127878000)|SYSTEM_METHOD_ENTRY|[19]|MAP<Id,Opportunity>.get(Object)
14:53:00.127 (127906000)|SYSTEM_METHOD_EXIT|[19]|MAP<Id,Opportunity>.get(Object)
14:53:00.138 (138538000)|SYSTEM_METHOD_ENTRY|[27]|String.valueOf(Object)
14:53:00.138 (138628000)|SYSTEM_METHOD_EXIT|[27]|String.valueOf(Object)
14:53:00.138 (138653000)|SYSTEM_METHOD_ENTRY|[27]|System.debug(ANY)
14:53:00.138 (138660000)|USER_DEBUG|[27]|DEBUG|*****Product-False***Opportunity:{Product__c=false, 3rdParty__c=false, Service__c=false}
14:53:00.138 (138669000)|SYSTEM_METHOD_EXIT|[27]|System.debug(ANY)
14:53:00.138 (138754000)|SYSTEM_METHOD_ENTRY|[36]|String.valueOf(Object)
14:53:00.138 (138816000)|SYSTEM_METHOD_EXIT|[36]|String.valueOf(Object)
14:53:00.138 (138830000)|SYSTEM_METHOD_ENTRY|[36]|System.debug(ANY)
14:53:00.138 (138836000)|USER_DEBUG|[36]|DEBUG|*****Service-False***Opportunity:{Product__c=false, 3rdParty__c=false, Service__c=false}
14:53:00.138 (138843000)|SYSTEM_METHOD_EXIT|[36]|System.debug(ANY)
14:53:00.138 (138896000)|SYSTEM_METHOD_ENTRY|[45]|String.valueOf(Object)
14:53:00.138 (138961000)|SYSTEM_METHOD_EXIT|[45]|String.valueOf(Object)
14:53:00.138 (138976000)|SYSTEM_METHOD_ENTRY|[45]|System.debug(ANY)
14:53:00.138 (138981000)|USER_DEBUG|[45]|DEBUG|*****3rdParty-False***Opportunity:{Product__c=false, 3rdParty__c=false, Service__c=false}
14:53:00.140 (140151000)|SYSTEM_METHOD_EXIT|[126]|System.debug(ANY)
14:53:00.140 (140205000)|SYSTEM_METHOD_ENTRY|[129]|MAP<Id,Opportunity>.put(Object, Object)
14:53:00.140 (140238000)|SYSTEM_METHOD_EXIT|[129]|MAP<Id,Opportunity>.put(Object, Object)
14:53:00.140 (140250000)|SYSTEM_METHOD_ENTRY|[17]|system.ListIterator.hasNext()
14:53:00.140 (140264000)|SYSTEM_METHOD_EXIT|[17]|system.ListIterator.hasNext()
14:53:00.140 (140284000)|SYSTEM_METHOD_ENTRY|[150]|MAP<Id,Opportunity>.values()
14:53:00.140 (140348000)|SYSTEM_METHOD_EXIT|[150]|MAP<Id,Opportunity>.values()
14:53:00.140 (140380000)|DML_BEGIN|[150]|Op:Update|Type:Opportunity|Rows:1
14:53:00.173 (173368000)|CODE_UNIT_STARTED|[EXTERNAL]|Validation:Opportunity:006S0000006d7VS
Opportunity trigger event AfterUpdate for [006S0000006d7VS]
14:53:00.246 (246820000)|SYSTEM_METHOD_ENTRY|[2]|LIST<Opportunity>.iterator()
14:53:00.247 (247157000)|SYSTEM_METHOD_EXIT|[2]|LIST<Opportunity>.iterator()
14:53:00.247 (247186000)|SYSTEM_METHOD_ENTRY|[2]|system.ListIterator.hasNext()
14:53:00.247 (247204000)|SYSTEM_METHOD_EXIT|[2]|system.ListIterator.hasNext()
14:53:00.247 (247259000)|SYSTEM_METHOD_ENTRY|[2]|system.ListIterator.hasNext()
14:53:00.247 (247272000)|SYSTEM_METHOD_EXIT|[2]|system.ListIterator.hasNext()
14:53:00.281 (247293000)|CUMULATIVE_LIMIT_USAGE
14:53:00.281|LIMIT_USAGE_FOR_NS|(default)|
Number of SOQL queries: 1 out of 100
Number of query rows: 1 out of 50000
Number of SOSL queries: 0 out of 20
Number of DML statements: 1 out of 150
Number of DML rows: 1 out of 10000
Number of code statements: 32 out of 200000
Maximum heap size: 0 out of 6000000
Number of callouts: 0 out of 10
Number of Email Invocations: 0 out of 10
Number of fields describes: 0 out of 100
Number of record type describes: 0 out of 100
Number of child relationships describes: 0 out of 100
Number of picklist describes: 0 out of 100
Number of future calls: 0 out of 10

14:53:00.281|CUMULATIVE_LIMIT_USAGE_END

14:53:00.247 (247333000)|CODE_UNIT_FINISHED|CreateAssetonClosedWon on Opportunity trigger event AfterUpdate for [006S0000006d7VS]
14:53:00.251 (251419000)|CODE_UNIT_STARTED|[EXTERNAL]|01qS00000004kUr|cloneOpportunity on Opportunity trigger event AfterUpdate for [006S0000006d7VS]
14:53:00.251 (251611000)|SYSTEM_CONSTRUCTOR_ENTRY|[3]|<init>()
14:53:00.251 (251641000)|SYSTEM_CONSTRUCTOR_EXIT|[3]|<init>()
14:53:00.251 (251678000)|SYSTEM_METHOD_ENTRY|[5]|LIST<Opportunity>.iterator()
14:53:00.251 (251707000)|SYSTEM_METHOD_EXIT|[5]|LIST<Opportunity>.iterator()
14:53:00.251 (251720000)|SYSTEM_METHOD_ENTRY|[5]|system.ListIterator.hasNext()
14:53:00.251 (251735000)|SYSTEM_METHOD_EXIT|[5]|system.ListIterator.hasNext()
14:53:00.251 (251820000)|SYSTEM_METHOD_ENTRY|[5]|system.ListIterator.hasNext()
14:53:00.251 (251834000)|SYSTEM_METHOD_EXIT|[5]|system.ListIterator.hasNext()
14:53:00.251 (251852000)|SYSTEM_METHOD_ENTRY|[16]|LIST<Opportunity>.isEmpty()
14:53:00.251 (251882000)|SYSTEM_METHOD_EXIT|[16]|LIST<Opportunity>.isEmpty()
14:53:00.286 (251904000)|CUMULATIVE_LIMIT_USAGE
14:53:00.286|LIMIT_USAGE_FOR_NS|(default)|
Number of SOQL queries: 1 out of 100
Number of query rows: 1 out of 50000
Number of SOSL queries: 0 out of 20
Number of DML statements: 1 out of 150
Number of DML rows: 1 out of 10000
Number of code statements: 35 out of 200000
Maximum heap size: 0 out of 6000000
Number of callouts: 0 out of 10
Number of Email Invocations: 0 out of 10
Number of fields describes: 0 out of 100
Number of record type describes: 0 out of 100
Number of child relationships describes: 0 out of 100
Number of picklist describes: 0 out of 100
Number of future calls: 0 out of 10

14:53:00.286|CUMULATIVE_LIMIT_USAGE_END

14:53:00.251 (251941000)|CODE_UNIT_FINISHED|cloneOpportunity on Opportunity trigger event AfterUpdate for [006S0000006d7VS]
14:53:00.252 (252048000)|CODE_UNIT_STARTED|[EXTERNAL]|Workflow:Opportunity
14:53:00.273 (273013000)|WF_RULE_EVAL_BEGIN|Assignment
14:53:00.273 (273038000)|WF_RULE_EVAL_BEGIN|Response
14:53:00.273 (273046000)|WF_RULE_EVAL_BEGIN|Workflow
14:53:00.273 (273072000)|WF_CRITERIA_BEGIN|[Opportunity: test 006S0000006d7VS]|Type = New Business|01Q70000000Fqmn|ON_ALL_CHANGES
14:53:00.276 (276780000)|WF_RULE_FILTER|[Opportunity : Opportunity Record Type equals New Business]
14:53:00.276 (276797000)|WF_RULE_EVAL_VALUE|012700000005kCr
14:53:00.276 (276802000)|WF_CRITERIA_END|false
14:53:00.276 (276814000)|WF_CRITERIA_BEGIN|[Opportunity: test 006S0000006d7VS]|Opportunity workflow to Live|01Q70000000Enfi|ON_CREATE_OR_TRIGGERING_UPDATE
14:53:00.276 (276864000)|WF_RULE_FILTER|[Opportunity : Stage equals Live]
AND [Account : Type equals Government, Employer, Health Plan, Hospital, Unions/Trusts, Partners, Association, Distributor, Brokers/Consultants]
14:53:00.276 (276878000)|WF_RULE_EVAL_VALUE|Stage 1 - Identify Target
14:53:00.276 (276882000)|WF_CRITERIA_END|false
14:53:00.276 (276891000)|WF_CRITERIA_BEGIN|[Opportunity: test 006S0000006d7VS]|Opportunity Stage 5 - Alert Acct Svcs Mgmt|01Q70000000FjyI|ON_CREATE_OR_TRIGGERING_UPDATE
14:53:00.277 (277061000)|WF_RULE_FILTER|[Opportunity : Stage equals Stage 5 - Contracting & Implementation]
AND [Opportunity : Annual Value greater than 10]
AND [Opportunity : Type equals Renewal]
14:53:00.277 (277076000)|WF_RULE_EVAL_VALUE|Stage 1 - Identify Target
14:53:00.277 (277080000)|WF_CRITERIA_END|false
14:53:00.277 (277090000)|WF_CRITERIA_BEGIN|[Opportunity: test 006S0000006d7VS]|Opportunity workflow [Account Type=Distributor]|01Q70000000EdBE|ON_CREATE_OR_TRIGGERING_UPDATE
14:53:00.277 (277132000)|WF_RULE_FILTER|[Opportunity : Stage equals Stage 5 - Contracting & Implementation]
AND [Account : Type equals Distributor]
AND [Opportunity : Type not equal to Billable Work Order]
14:53:00.277 (277145000)|WF_RULE_EVAL_VALUE|Stage 1 - Identify Target
14:53:00.277 (277148000)|WF_CRITERIA_END|false
14:53:00.277 (277157000)|WF_CRITERIA_BEGIN|[Opportunity: test 006S0000006d7VS]|Stage 5 - Billable WO - Distributor|01Q70000000FeD7|ON_CREATE_OR_TRIGGERING_UPDATE
14:53:00.277 (277840000)|WF_RULE_FILTER|[Account : Type equals Distributor]
AND [Opportunity : Type equals Billable Work Order]
AND [Opportunity : Stage equals Stage 5 - Contracting & Implementation]
AND [Opportunity : Contract Signature equals false]
14:53:00.277 (277858000)|WF_RULE_EVAL_VALUE|Health Plan
14:53:00.277 (277862000)|WF_CRITERIA_END|false
14:53:00.277 (277876000)|WF_CRITERIA_BEGIN|[Opportunity: test 006S0000006d7VS]|Type = Renewal|01Q70000000Fqms|ON_ALL_CHANGES
14:53:00.277 (277897000)|WF_RULE_FILTER|[Opportunity : Opportunity Record Type equals Renewal]
14:53:00.277 (277904000)|WF_RULE_EVAL_VALUE|012700000005kCr
14:53:00.277 (277908000)|WF_CRITERIA_END|false
14:53:00.294 (294134000)|SYSTEM_METHOD_ENTRY|[151]|MAP<Id,Opportunity>.values()
14:53:00.294 (294222000)|SYSTEM_METHOD_EXIT|[151]|MAP<Id,Opportunity>.values()
14:53:00.294 (294241000)|SYSTEM_METHOD_ENTRY|[151]|String.valueOf(Object)
14:53:00.294 (294312000)|SYSTEM_METHOD_EXIT|[151]|String.valueOf(Object)
14:53:00.294 (294328000)|SYSTEM_METHOD_ENTRY|[151]|System.debug(ANY)
14:53:00.294 (294335000)|USER_DEBUG|[151]|DEBUG|##########(Opportunity:{Product__c=false, 3rdParty__c=false, Service__c=false})
14:53:00.294 (294343000)|SYSTEM_METHOD_EXIT|[151]|System.debug(ANY)
14:53:00.328 (294362000)|CUMULATIVE_LIMIT_USAGE
14:53:00.328|LIMIT_USAGE_FOR_NS|(default)|
Number of SOQL queries: 1 out of 100
Number of query rows: 1 out of 50000
Number of SOSL queries: 0 out of 20
Number of DML statements: 1 out of 150
Number of DML rows: 1 out of 10000
Number of code statements: 36 out of 200000
Maximum heap size: 0 out of 6000000
Number of callouts: 0 out of 10
Number of Email Invocations: 0 out of 10
Number of fields describes: 0 out of 100
Number of record type describes: 0 out of 100
Number of child relationships describes: 0 out of 100
Number of picklist describes: 0 out of 100
Number of future calls: 0 out of 10

14:53:00.328|CUMULATIVE_LIMIT_USAGE_END

14:53:00.294 (294403000)|CODE_UNIT_FINISHED|FieldUpdates1 on OpportunityLineItem trigger event AfterUpdate for [00kS0000005SD0J]
14:53:00.294 (294412000)|EXECUTION_FINISHED
14:53:00.298 (298851000)|EXECUTION_STARTED
14:53:00.298 (298859000)|CODE_UNIT_STARTED|[EXTERNAL]|Workflow:OpportunityLineItem
14:53:00.317 (317053000)|WF_RULE_EVAL_BEGIN|Assignment
14:53:00.317 (317077000)|WF_RULE_EVAL_BEGIN|Response
14:53:00.317 (317085000)|WF_RULE_EVAL_BEGIN|Workflow
14:53:00.317 (317107000)|WF_CRITERIA_BEGIN|[Opportunity Product: 00kS0000005SD0J]|Update Prod Grp|01Q70000000Ft8H|ON_ALL_CHANGES
14:53:00.317 (317269000)|WF_FORMULA|Formula:TRUE|Values:
14:53:00.317 (317276000)|WF_CRITERIA_END|true
14:53:00.321 (321421000)|WF_ACTIONS_END| Field Update: 2;
14:53:00.321 (321427000)|CODE_UNIT_FINISHED|Workflow:OpportunityLineItem
14:53:00.321 (321434000)|EXECUTION_FINISHED

Vinit_KumarVinit_Kumar

It seems that you have modifed the code which I have pasted to use as the Trigger I pasted is on before event and your Debug log is after event.Please see below part of debug logs:-

 

|01qS00000004kj8|FieldUpdates1 on OpportunityLineItem trigger event AfterUpdate for [00kS0000005SD0J]

 

Also,please use my debug statement as I want to see the if condition which is being executed.

 

 

JN22JN22

Vinit,

 

Sorry, I tried that to see if it would be any different and forgot to switch back.  Below is the debug log as a Before trigger.  It appears as though the True conditions are not firing for some reason. 

 

27.0 APEX_CODE,DEBUG;APEX_PROFILING,INFO;CALLOUT,INFO;DB,INFO;SYSTEM,DEBUG;VALIDATION,INFO;VISUALFORCE,INFO;WORKFLOW,INFO

11:53:29.042 (42735000)|EXECUTION_STARTED

11:53:29.042 (42775000)|CODE_UNIT_STARTED|[EXTERNAL]|TRIGGERS

11:53:29.042 (42795000)|CODE_UNIT_STARTED|[EXTERNAL]|01qS00000004kjS|FieldUpdates1 on OpportunityLineItem trigger event BeforeUpdate for [00kS0000005SD0J]

11:53:29.044 (44109000)|SYSTEM_CONSTRUCTOR_ENTRY|[6]|<init>(Integer)

11:53:29.044 (44149000)|SYSTEM_CONSTRUCTOR_EXIT|[6]|<init>(Integer)

11:53:29.044 (44292000)|SYSTEM_METHOD_ENTRY|[8]|LIST<OpportunityLineItem>.iterator()

11:53:29.044 (44599000)|SYSTEM_METHOD_EXIT|[8]|LIST<OpportunityLineItem>.iterator()

11:53:29.044 (44626000)|SYSTEM_METHOD_ENTRY|[8]|system.ListIterator.hasNext()

11:53:29.044 (44658000)|SYSTEM_METHOD_EXIT|[8]|system.ListIterator.hasNext()

11:53:29.044 (44773000)|SYSTEM_METHOD_ENTRY|[9]|SET<Id>.add(Object)

11:53:29.044 (44801000)|SYSTEM_METHOD_EXIT|[9]|SET<Id>.add(Object)

11:53:29.044 (44811000)|SYSTEM_METHOD_ENTRY|[8]|system.ListIterator.hasNext()

11:53:29.044 (44822000)|SYSTEM_METHOD_EXIT|[8]|system.ListIterator.hasNext()

11:53:29.045 (45370000)|SOQL_EXECUTE_BEGIN|[12]|Aggregations:0|select Id, Product__c, Service__c, 3rdParty__c from Opportunity where Id = :tmpVar1

11:53:29.048 (48658000)|SOQL_EXECUTE_END|[12]|Rows:1

11:53:29.048 (48776000)|SYSTEM_METHOD_ENTRY|[16]|LIST<OpportunityLineItem>.iterator()

11:53:29.048 (48802000)|SYSTEM_METHOD_EXIT|[16]|LIST<OpportunityLineItem>.iterator()

11:53:29.048 (48812000)|SYSTEM_METHOD_ENTRY|[16]|system.ListIterator.hasNext()

11:53:29.048 (48825000)|SYSTEM_METHOD_EXIT|[16]|system.ListIterator.hasNext()

11:53:29.048 (48870000)|SYSTEM_METHOD_ENTRY|[18]|MAP<Id,Opportunity>.get(Object)

11:53:29.048 (48894000)|SYSTEM_METHOD_EXIT|[18]|MAP<Id,Opportunity>.get(Object)

11:53:29.059 (59922000)|SYSTEM_METHOD_ENTRY|[26]|String.valueOf(Object)

11:53:29.059 (59988000)|SYSTEM_METHOD_EXIT|[26]|String.valueOf(Object)

11:53:29.060 (60014000)|SYSTEM_METHOD_ENTRY|[26]|System.debug(ANY)

11:53:29.060 (60023000)|USER_DEBUG|[26]|DEBUG|*****2***Opportunity:{Product__c=false, 3rdParty__c=false, Service__c=false, Id=006S0000006d7VSIAY}

11:53:29.060 (60031000)|SYSTEM_METHOD_EXIT|[26]|System.debug(ANY)

11:53:29.060 (60117000)|SYSTEM_METHOD_ENTRY|[35]|String.valueOf(Object)

11:53:29.060 (60158000)|SYSTEM_METHOD_EXIT|[35]|String.valueOf(Object)

11:53:29.060 (60171000)|SYSTEM_METHOD_ENTRY|[35]|System.debug(ANY)

11:53:29.060 (60176000)|USER_DEBUG|[35]|DEBUG|*****4***Opportunity:{Product__c=false, 3rdParty__c=false, Service__c=false, Id=006S0000006d7VSIAY}

11:53:29.060 (60182000)|SYSTEM_METHOD_EXIT|[35]|System.debug(ANY)

11:53:29.060 (60235000)|SYSTEM_METHOD_ENTRY|[44]|String.valueOf(Object)

11:53:29.060 (60273000)|SYSTEM_METHOD_EXIT|[44]|String.valueOf(Object)

11:53:29.060 (60285000)|SYSTEM_METHOD_ENTRY|[44]|System.debug(ANY)

11:53:29.060 (60290000)|USER_DEBUG|[44]|DEBUG|*****6***Opportunity:{Product__c=false, 3rdParty__c=false, Service__c=false, Id=006S0000006d7VSIAY}

11:53:29.060 (60296000)|SYSTEM_METHOD_EXIT|[44]|System.debug(ANY)

11:53:29.060 (60344000)|SYSTEM_METHOD_ENTRY|[47]|MAP<Id,Opportunity>.put(Object, Object)

11:53:29.060 (60372000)|SYSTEM_METHOD_EXIT|[47]|MAP<Id,Opportunity>.put(Object, Object)

11:53:29.060 (60383000)|SYSTEM_METHOD_ENTRY|[16]|system.ListIterator.hasNext()

11:53:29.060 (60397000)|SYSTEM_METHOD_EXIT|[16]|system.ListIterator.hasNext()

11:53:29.060 (60417000)|SYSTEM_METHOD_ENTRY|[51]|MAP<Id,Opportunity>.values()

11:53:29.060 (60454000)|SYSTEM_METHOD_EXIT|[51]|MAP<Id,Opportunity>.values()

11:53:29.060 (60495000)|DML_BEGIN|[51]|Op:Update|Type:Opportunity|Rows:1

11:53:29.094 (94877000)|CODE_UNIT_STARTED|[EXTERNAL]|Validation:Opportunity:006S0000006d7VS

11:53:29.594|LIMIT_USAGE_FOR_NS|(default)|  

Number of SOQL queries: 1 out of 100  

Number of query rows: 1 out of 50000  

Number of SOSL queries: 0 out of 20  

Number of DML statements: 1 out of 150  

Number of DML rows: 1 out of 10000  

Number of code statements: 14 out of 200000  

Maximum heap size: 0 out of 6000000  

Number of callouts: 0 out of 10  

Number of Email Invocations: 0 out of 10  

Number of fields describes: 0 out of 100  

Number of record type describes: 0 out of 100  

Number of child relationships describes: 0 out of 100  

Number of picklist describes: 0 out of 100  

Number of future calls: 0 out of 10

11:53:29.594|CUMULATIVE_LIMIT_USAGE_END

11:53:29.278 (278346000)|CODE_UNIT_FINISHED|TRIGGERS

11:53:29.278 (278364000)|EXECUTION_FINISHED

Vinit_KumarVinit_Kumar

So,this is pretty clear you are going in the else condition not in the if condition where you are updating it  to true.Can you check the records which is being updated satisfies your if conition like 

 

(OppLine2.Product_Group__c == 'Product') && (OppLine2.Product_Family__c == 'Group 1')

 

check the record is populated as 

Product_Group__c == 'Product' and Product_Family__c == 'Group 1' for these fields