You need to sign in to do that
Don't have an account?
GMASJ
Trigger is not firing.
Hi,
I want to update entitlement fields from opportunitylines below is the code written not sure what the issue is it is not firring the update. Please suggest me the change.
SD
I want to update entitlement fields from opportunitylines below is the code written not sure what the issue is it is not firring the update. Please suggest me the change.
trigger update_entitlement_product on OpportunityLineItem (after insert, after update) { system.debug('Opportunity Line Items Trigger Started.....'); EntitlementUtil.UpdateEntitlementDate(trigger.new); }
public with sharing class EntitlementUtil { public static void UpdateEntitlementDate(List<OpportunityLineItem> newLst){ set<id> oppid = new set<id>(); list<entitlement> ent = new list<entitlement>(); for(OpportunityLineItem opp: newLst){ oppid.add(opp.id); } for(opportunity ops: [select NS_Start_Date_Min__c,NS_End_Date_Max__c from opportunity where id in :oppid]){ system.debug('Opportunity Lines NS_Start_Date_Min__c :' + ops.NS_Start_Date_Min__c); system.debug('Opportunity Lines NS_End_Date_Max__c :' + ops.NS_End_Date_Max__c); for(entitlement etl : [select Opportunity__c,StartDate,EndDate from Entitlement where Opportunity__c in :oppid]){ system.debug('Entitlement StartDate :' + etl.StartDate); system.debug('Entitlement EndDate :' + etl.EndDate); etl.StartDate = ops.NS_Start_Date_Min__c; etl.EndDate = ops.NS_End_Date_Max__c; ent.add(etl); } } if(ent.size() > 0){ system.debug('Entitlement dates are updated'); update ent; } } }Thanks
SD
Please find the optimized version of the above code...
Hope this helps...!!!
Please mark as best answer if the above helps....!!!
All Answers
Were you able to get these two statements executed ?
system.debug('Opportunity Lines NS_Start_Date_Min__c :' + ops.NS_Start_Date_Min__c);
14 system.debug('Opportunity Lines NS_End_Date_Max__c :' + ops.NS_End_Date_Max__c);
Bcoz, I could see you are trying to get Opportunities with Opportunity line item ids ... and you have included a for loop inside a for lool with query
Change the entire second for like below:
for(entitlement etl : [select Opportunity__c,StartDate,EndDate from Entitlement where Opportunity__c = : ops.id])
{
entitlement ET = new entitlement(id = etl.id);
ET.StartDate = ops.NS_Start_Date_Min__c;
ET.EndDate = ops.NS_End_Date_Max__c;
system.debug('Entitlement StartDate :' + ET.StartDate);
system.debug('Entitlement EndDate :' + ET.EndDate);
ent.add(ET);
}
Can you please Let me know if it helps or not!!!
If it helps don't forget to mark this as a best answer!!!
Thanks,
Raj
Please find the optimized version of the above code...
Hope this helps...!!!
Please mark as best answer if the above helps....!!!
Please let me know if you know why it is auto deleted. There is not other process or custom code is in conflict.
Thanks
Sudhir
Yes your right also even if we directly update from entitlement enddate it is getting auto deleted.
This delete is happenig only if opportuntiy is associated to entitlement. if there is no opportunity it is allowing me to update the enddate.
Opportunity look up is in below screen shot under Opportunity information.
Thanks
Sudhir