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
Chad KovacChad Kovac 

Apex Trigger. No Errors but also no results.

I'm trying to update an Opportunity OEM_Make__c field with a comma delim list of Manufacturers from a Subgroup.  Opportunity->Group->SubGroup.

I receive no errors but it doesn't seem to be updating anything... ?
Opportunity_ID__c is the Opportunity ID that the Subgroup is related to (through the Group): Opportunity_Group__r.Opportunity__r.Id

trigger UpdateOEMonOpportunity on Opportunity_SubGroup__c (before insert, before update) {
String strOEMs;
String strComma;
Set<Id> OppIds = new Set<Id>();
for (Opportunity_Subgroup__c sg : Trigger.new) {
  OppIds.add(sg.Opportunity_ID__c);
}

strOEMs = Null;
strComma = Null;

List<Opportunity> Opps = new List<Opportunity>{};

if (OppIds.size() > 0) {
  for(Opportunity_SubGroup__c OSG : [Select Opportunity_ID__c, Manufacturer__c from Opportunity_Subgroup__c where Opportunity_ID__c in :OppIds]) {
   if(OSG.Manufacturer__c!=Null) {
    strOEMs=strOEMs + strComma + OSG.Manufacturer__c;
          strComma = ', ';
   }
   Opps.Add(
    new Opportunity(
     OEM_Make__c = strOEMs,
     ID=OSG.Opportunity_ID__c
    ));
  }
  if(!Opps.IsEmpty()) {Update Opps;}
}
}


Best Answer chosen by Chad Kovac
Chad KovacChad Kovac
I ended up adding this functionality to another class that I knew to work.

All Answers

PrasanntaPrasannta (Salesforce Developers) 
Hi,

Please try setting the debug logs for that user from which you are trying to update the value and check whether the trigger is firing or not.
You can also check in the debug logs how the execution of trigger is going and where is causing the issue if the trigger is firing.
PrasanntaPrasannta (Salesforce Developers) 
Here are the steps to set the debug logs-
Under setup>logs>Debug Logs

1.Click on 'New' button
2. Add the name of the user you have logged in.
3.Click 'Save' button.
Chad KovacChad Kovac
Thanks Prasannta!  Here's what the debug log tells me...

10:18:17.122 (122228000)|SOQL_EXECUTE_BEGIN|[4]|Aggregations:0|select Select_This_SubGroup_For_Opportunity__c from Opportunity_SubGroup__c where ((Id != :tmpVar1 and Opportunity_Group__c = :tmpVar2) and Select_This_SubGroup_For_Opportunity__c = true)
10:18:17.130 (130625000)|SOQL_EXECUTE_END|[4]|Rows:0

Then below that a bit...
10:18:17.151 (151571000)|CODE_UNIT_STARTED|[EXTERNAL]|01qm00000004DWh|UpdateOEMonOpportunity on Opportunity_SubGroup trigger event BeforeUpdate for [a01m0000000LqNB]
10:18:17.151 (151887000)|SYSTEM_CONSTRUCTOR_ENTRY|[4]|<init>(Integer)
10:18:17.151 (151917000)|SYSTEM_CONSTRUCTOR_EXIT|[4]|<init>(Integer)
10:18:17.151 (151952000)|SYSTEM_METHOD_ENTRY|[5]|LIST<Opportunity_SubGroup__c>.iterator()
10:18:17.152 (152202000)|SYSTEM_METHOD_EXIT|[5]|LIST<Opportunity_SubGroup__c>.iterator()
10:18:17.152 (152239000)|SYSTEM_METHOD_ENTRY|[5]|system.ListIterator.hasNext()
10:18:17.152 (152260000)|SYSTEM_METHOD_EXIT|[5]|system.ListIterator.hasNext()
10:18:17.168 (168453000)|SYSTEM_METHOD_ENTRY|[6]|SET<Id>.add(Object)
10:18:17.168 (168511000)|SYSTEM_METHOD_EXIT|[6]|SET<Id>.add(Object)
10:18:17.168 (168523000)|SYSTEM_METHOD_ENTRY|[5]|system.ListIterator.hasNext()
10:18:17.168 (168538000)|SYSTEM_METHOD_EXIT|[5]|system.ListIterator.hasNext()
10:18:17.168 (168623000)|SYSTEM_CONSTRUCTOR_ENTRY|[12]|<init>()
10:18:17.168 (168646000)|SYSTEM_CONSTRUCTOR_EXIT|[12]|<init>()
10:18:17.168 (168669000)|SYSTEM_METHOD_ENTRY|[14]|SET<Id>.size()
10:18:17.168 (168694000)|SYSTEM_METHOD_EXIT|[14]|SET<Id>.size()
10:18:17.169 (169019000)|SOQL_EXECUTE_BEGIN|[15]|Aggregations:0|select Opportunity_ID__c, Manufacturer__c from Opportunity_Subgroup__c 
10:18:17.187 (187273000)|SOQL_EXECUTE_END|[15]|Rows:0
10:18:17.187 (187348000)|SYSTEM_METHOD_ENTRY|[15]|Database.QueryLocator.iterator()
10:18:17.187 (187506000)|SYSTEM_METHOD_ENTRY|[7]|QueryLocatorIterator.QueryLocatorIterator()
10:18:17.187 (187518000)|SYSTEM_METHOD_EXIT|[7]|QueryLocatorIterator
10:18:17.187 (187571000)|SYSTEM_METHOD_EXIT|[15]|Database.QueryLocator.iterator()
10:18:17.187 (187593000)|SYSTEM_METHOD_ENTRY|[15]|Database.QueryLocatorIterator.hasNext()
10:18:17.187 (187617000)|SYSTEM_METHOD_EXIT|[15]|Database.QueryLocatorIterator.hasNext()
10:18:17.187 (187667000)|SYSTEM_METHOD_ENTRY|[26]|LIST<Opportunity>.isEmpty()
10:18:17.187 (187692000)|SYSTEM_METHOD_EXIT|[26]|LIST<Opportunity>.isEmpty()
10:18:18.015 (187717000)|CUMULATIVE_LIMIT_USAGE
10:18:18.015|LIMIT_USAGE_FOR_NS|(default)|
  Number of SOQL queries: 2 out of 100
  Number of query rows: 0 out of 50000
  Number of SOSL queries: 0 out of 20
  Number of DML statements: 0 out of 150
  Number of DML rows: 0 out of 10000
  Maximum CPU time: 0 out of 10000
  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

10:18:18.015|CUMULATIVE_LIMIT_USAGE_END

10:18:17.187 (187801000)|CODE_UNIT_FINISHED|UpdateOEMonOpportunity on Opportunity_SubGroup trigger event BeforeUpdate for [a01m0000000LqNB]

Is it not finding the right ID or something?

I added some debug lines and ran it again and apparently Opps.IsEmpty() is true so I debugged further back and found that apparently it's never entering the loop here:
for(Opportunity_SubGroup__c OSG : [Select Opportunity_ID__c, Manufacturer__c from Opportunity_Subgroup__c where Opportunity_ID__c in :OppIds])

So there must be something wrong with OppIds?  Is this the wrong way to do this SOQL?
Above this loop I'm assigning OppIds:
OppIds.add(sg.Opportunity_ID__c);



PrasanntaPrasannta (Salesforce Developers) 
Hi,

Since its not throwing any error, I guess 'OppIds' is empty. Thats why its not entering the for loop.
Set the system.debug and check it value. If it coming empty. Check where have you set its value and what went wrong.
Use System.debug at places where necessary.
Chad KovacChad Kovac
I still haven't managed to get past this... anyone?

Chad KovacChad Kovac
I ended up adding this functionality to another class that I knew to work.

This was selected as the best answer