You need to sign in to do that
Don't have an account?
Mani Kandan01
WHERE shipDate__c >= :startDate AND return_date__c <= :endDate
In the above code startDate & endDate retrives the data (already Inserted Record) from db.
for eg:
startDate = 20-03-2021
endDate = 16-04-2021
WHERE shipDate__c >= :20-03-2021 AND return_date__c <= :16-04-2021
but what i need is, While editing the record by changing startDate, it retrives the entered data before saving in db.
for eg:
startDate = 26-03-2021
WHERE shipDate__c >= :26-03-2021 AND return_date__c <= :16-04-2021
Hope someone will help
Thank you
how to get input value using apex trigger
public void onBeforeUpdate(List<Opportunity> newMap){ Set<String> oppIds = new Set<String>(); for(Opportunity opp: newMap){ oppIds.add(opp.id); } if(oppIds.size() > 0 && oppIds != null){ //get all record of product with Opp Id List<OpportunityLineItem> productList = [SELECT Product2.m_ProductGroup__r.Name, OpportunityId, Opportunity.shipDate__c, Opportunity.return_date__c FROM OpportunityLineItem WHERE OpportunityId IN :oppIds AND IsDeleted = false ]; if(productList.size() > 0 && productList !=null){ for(OpportunityLineItem product: productList){ totalUsed = 0; String name = product.Product2.m_ProductGroup__r.Name; Date startDate = product.Opportunity.shipDate__c; Date endDate = product.Opportunity.return_date__c; if(name != ''){ totalUsed = getSum(name, startDate, endDate); if( totalUsed <= 30 ){ for(Opportunity opp: newMap) { opp.m_enableproduct__c = true; } } } } } } } //end BeforeUpdate private Decimal getSum(String productName, Date startDate, Date endDate){ Decimal sum = 0; List<Opportunity> dataList = new List<Opportunity>(); List<OpportunityLineItem> productList = new List<OpportunityLineItem>(); dataList = [SELECT id, shipDate__c, return_date__c FROM Opportunity WHERE shipDate__c >= :startDate AND return_date__c <= :endDate]; if(dataList != null && dataList.size() > 0){ for(Opportunity opp :dataList){ productList = [SELECT Quantity FROM OpportunityLineItem WHERE OpportunityId =:opp.id AND Product2.m_ProductGroup__r.Name =: productName AND IsDeleted = false ]; if(productList != null && productList.size() > 0 ){ for(OpportunityLineItem addTemp :productList){ sum += addTemp.Quantity; } } } system.debug('sum' + sum); } return sum; }Hi Everyone help me to get output.
WHERE shipDate__c >= :startDate AND return_date__c <= :endDate
In the above code startDate & endDate retrives the data (already Inserted Record) from db.
for eg:
startDate = 20-03-2021
endDate = 16-04-2021
WHERE shipDate__c >= :20-03-2021 AND return_date__c <= :16-04-2021
but what i need is, While editing the record by changing startDate, it retrives the entered data before saving in db.
for eg:
startDate = 26-03-2021
WHERE shipDate__c >= :26-03-2021 AND return_date__c <= :16-04-2021
Hope someone will help
Thank you
It sounds like you are changing the value in shipDate on the record, and want to get the new value in a before trigger?
Ex: Date startDate = product.Opportunity.shipDate__c;
You are getting the old value because you are querying existing records in productList. You can retrieve the new value from Trigger.newMap.
Date startDate =Trigger.newMap.get(product.OpportinityId).shipDate__c;
Good luck,
Daniel
There are some great samples in the doc
when i use
Date startDate =Trigger.newMap.get(product.OpportinityId).shipDate__c;
it throws me an error called Variable does not exist: shipDate__c