You need to sign in to do that
Don't have an account?
Pavan Sonare
how can I prevent to update the 'Due_Date__C' date from updating everyday for below code?
Group_or_Party_Payout__c objGroupPayout = new Group_or_Party_Payout__c( Rebate_Program__c = strPGID, Rebate_Program_Payout_Period__c = strPeriodID, Account__c = strAccountId, Calculation_Date__c = date.today(), Gross_Dollar_Rebates__c = (Decimal)mapDetail.get(GROSS_DOLLAR) == null ? 0 : (Decimal)mapDetail.get(GROSS_DOLLAR), Gross_Per_Pound_Rebates__c = (Decimal)mapDetail.get(GROSS_PER_POUND) == null ? 0 : (Decimal)mapDetail.get(GROSS_PER_POUND), Calculated_Rebate_Amount__c = ((Decimal)mapDetail.get(GROSS_DOLLAR) == null ? 0 : (Decimal)mapDetail.get(GROSS_DOLLAR)) + ((Decimal)mapDetail.get(GROSS_PER_POUND) == null ? 0 : (Decimal)mapDetail.get(GROSS_PER_POUND)), Rebate_23100__c = decRebate23100, Commission_23190_Tax__c = decCommission23100, Advertising_23120__c = decAdvertising, Total_Approved_Adjustment_Amount__c = (Decimal)mapDetail.get(ADJUSTMENT) == null ? 0 : (Decimal)mapDetail.get(ADJUSTMENT), Name = strPGName + '-' + strPeriodName, Due_Date__c = date.today(), External_ID__c = strPGID + '-' + strPeriodID + '-' + strAccountId, Delinquent_Accounts__c = (String)mapDetail.get(DELINQUENT), Org_ID2__c = (String)mapDetail.get(ORG_ID), Invoice_Description__c = strInvoiceDesc, Cash_Discount2__c = decCashDisc, Fuel_Surcharge__c = decFuelSur, Status__c = 'Draft' ); lstGroupPayout.add(objGroupPayout); } } system.debug('List of group or part payouts =>' + lstGroupPayout); // List of group or party payout. Integer intSuccessCount = 0; Integer intFailureCount = 0; String strFailureInfo = ''; Schema.SObjectField externalId = Group_or_Party_Payout__c.Fields.External_ID__c; Database.UpsertResult[] srList = Database.upsert(lstGroupPayout, externalId, false);
I just want the due date to be set at as when the record is created and not update everyday
(This is a batch class that runs everynight)
You should modify your code to set the Due_Date__c field only during the initial creation (insert) and not update it during upsert.
Here's a code that you'll have to adapt to your object Group_or_Party_Payout__c and change the field "External_ID__c". This is just an example of how you can modify your code to set the Due_Date__c only for the insert:
This code checks if a record with the same External_ID__c already exists.
Please mark this comment as best answer if it's help you.
below is the modified class as per your suggestion, but now its not updating any other fields like it used to.