You need to sign in to do that
Don't have an account?
John Gerhard
Dynamic SOQL and Dynamic fields from a variable?
Hello Everyone,
I can't figure this one out. Basically, I am assigning the API label of a field on my opportunity to a product field to easily create a list called oppFieldsList. Run a SOQL to grab all the fields and then go through and update those fields on the opportunity with the unit price. Here is my code snippet, hopefully someone has the right idea so I don't have to create if elses for 150 fields >.< Thank you in advance!
I can't figure this one out. Basically, I am assigning the API label of a field on my opportunity to a product field to easily create a list called oppFieldsList. Run a SOQL to grab all the fields and then go through and update those fields on the opportunity with the unit price. Here is my code snippet, hopefully someone has the right idea so I don't have to create if elses for 150 fields >.< Thank you in advance!
trigger OpportunityLineItemAfterUpdateAfterInsert on OpportunityLineItem (after update, after insert) { List<ID> oppIDList = new List<ID>(); List<String> oppFieldsList = new List<String>(); List<Opportunity> oppFieldsToUpdate = new List<Opportunity>(); Integer i = 0; for (OpportunityLineItem oppLI : Trigger.new) { oppIDList.add(oppLI.OpportunityId); oppFieldsList.add(oppLI.Opportunity_Product_Field__c); } List<Opportunity> oppFields = [SELECT oppFieldsList FROM Opportunity WHERE Id IN: oppIDList]; for (OpportunityLineItem oppLI : Trigger.new) { oppFieldsToUpdate.add(oppFields.put(oppFieldsList[i],oppLI.UnitPrice)); i++; } update oppFieldsToUpdate; }
All Answers
1) http://amitsalesforce.blogspot.com/2014/11/dynamic-field-mapping-using-custom.html
Try to update your code like below
Let us know if this will help you
Let us know if this will work