i am facing an issue on opportunity product. i develop a code where i am checking 'credit unused product count' on opportunity line item. if this is greater than zero my code push Regional director name on opportunity. problem here is after i add a product to an opportunity from price book and click on save button, then i am prompting to opportunity detail page. As soon as i am prompting to here i see director name is null. if i refresh my page, director name is populating over there. But my users don't want to refresh all the times.can you please some one help me how to resolve this? what is reason behind this issue? attached my piece code here.

public with sharing class OpptyDiscountFieldUpdateUtil{
    public static void OpptyUpdateTriggerone(List<id> opportunityids){
for(ID oppid:opportunityids){
  List<Opportunity> oppList = querying  some fields
  List<opportunitylineitem>  opplinerolluplist = [select id,OpportunityId,Credit_Unused_product__c, Protecode_Product__c from OpportunityLineItem WHERE OpportunityId IN:oppList];    

if(oppList.size()> 0){
for(Opportunity opp:oppList){
     List<OpportunityLineItem> tempList = new List<OpportunityLineItem>();
                   for(OpportunityLineItem oppLinItem:opplinerolluplist){
                     if(oppLinItem.OpportunityId == opp.Id ){
                   // Create a Map of Opportunity and its LineItems 

            for(Opportunity opp:oppList){
            for(OpportunityLineItem oppLinItem :OppMap2.get(opp.Id)){

                   if(oppLinItem.Credit_Unused_product__c > 0){

                    Opp.Credit_Unused_Approval__c = true;

                    if( opp.Credit_Unused_Approval__c == true){
                            // Find all the values in the custom setting
                            Map<String, Project_PL_PeL_PP_LT_CC__c> CCCustomSetMap = Project_PL_PeL_PP_LT_CC__c.getAll();

                            // Sort them by name
                            List<String> Rules2 = new List<String>();

                            String CCKey = 'CC';
                            Project_PL_PeL_PP_LT_CC__c CCRules = CCCustomSetMap.get(CCKey);

                            if(CCRules != null){ 
                                CCAppr1 = CCRules.CC_Approver1__c;


                            for(User u:AllUsers){
                                if(u.Name == CCAppr1){
                                    Opp.CC_Level1__c = u.Id;




                } else {
                    Opp.Credit_Unused_Approval__c = false;
                    Opp.CC_Level1__c = null;
                    Opp.CC_Level2__c = null;
                    Opp.CC_Level3__c = null;
                    Opp.CC_Level4__c = null;



if(Opp.Credit_Unused_Approval__c == true){
if(updtoppList1.size()>0) update updtoppList1;
  • as a service to the Community and to yourself, please format the above code using edit so it is indented in a way that makes sense. That said, @brovasi has the answer - future methods execute async and results can't be seen until user refreshes page seconds later.
    – cropredy
    Aug 24, 2016 at 23:37

1 Answer 1


Your problem is you marked your method as future which will execute your method asyncronously(running in the background). Now we are missing a bit of context here on how you call your method.More info here

But if you want to update something on opportunity from Opportunity Product, I would advice you to firstly remove this @future and call your method after update/insert.

You might have to change a bit your code to make it work but shouldn't be too difficult if you know your code.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .