You need to sign in to do that
Don't have an account?
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
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;} } }
All Answers
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.
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.
Then below that a bit...
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:
So there must be something wrong with OppIds? Is this the wrong way to do this SOQL?
Above this loop I'm assigning OppIds:
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.