I have a helper class that upserts custom object records based off the Opportunitylineitem. In October we switched a lot of logic around and are using new picklist/lookups and we did not update historical OpportunityLineitem data. But we are updating the custom object records. So, if a new record is created with the new fields everything works. However, if a historical OLI record is updated it updates null values into picklists that I manually populated.
Example:
public static void createRevPipe(List<OpportunityLineItem> scope)
{
List<Revenue_Pipeline__c> revPipelineToUpsert = new List<Revenue_Pipeline__c>();
for(OpportunityLineItem oli : scope)
{
revPipelineToUpsert.add(new Revenue_Pipeline__c(
Account__c = oli.Opportunity.AccountId,
Product_Type__c = oli.Product_Type__c,
Product_Type__c is my new field if it's populated the mapping works, if it's not it's pushes null which clears out the field on the Revenue_Pipeline__c if I've come along after and done a data load to populate it.
I know I can do something like:
String pType;
if(oli.Product_Type__c != null)
pType = oli.Product_Type__c;
then Product_type__c = ptype;
I'm struggling with how I can check for a null value and stop the mapping of the field.
Thoughts?
Edit:
You cannot do if statements in between parenthesis (). The question is how to do an if in the () if you cannot.