• Muhammad Moneeb
  • NEWBIE
  • 25 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 8
    Questions
  • 8
    Replies
Hi,
i have a process in process builder which changes the field (Status -- > picklist) (Market -- > picklist)

If Status changes to Budget we change Market to Budget
If Market changes to Budget we change Status to Budget. 
and its going recursive how do i stop that 
 
i am working on a trigger in its giving cpu limit exceeded error can anyone help me here is my code 
 
trigger OPP_Percentage_Change on Opportunity (after update,after insert) {
    if(Trigger.isUpdate){
    List<Opportunity> OppToPass = new List<Opportunity>();
    Map<id,Opportunity> MapToPass = new Map<Id,Opportunity>();
    for(Opportunity opp : Trigger.new){
        OppToPass.add(opp);
    }
    for(Opportunity OppOld: Trigger.Old){
        MapToPass.put(OppOld.Id, OppOld);
    }
    if(OppToPass.size()>0 && MapToPass.size()>0){
        SaleOrderOpportunityTriggersHandler.Opp_Percentage_Change(OppToPass,MapToPass);
        SaleOrderOpportunityTriggersHandler.OppAmount(OppToPass);
    }
    }
    
    
}

here is class function 
public static void Opp_Percentage_Change(List<Opportunity> OppForPercentage,Map<id,Opportunity> OldMap){
     Set<Id> OppSet = new Set<Id>();
     Map<Id,Sales_Order__c> SoToUpdate = new Map<Id,Sales_Order__c>();
        Map<Id,Sales_Order__c> mapSo = new Map<Id,Sales_Order__c>();
        for (Opportunity opp : OppForPercentage){
            OppSet.add(OPP.Id);
        }
        for(Sales_Order__c SO : [Select Quote_Odds__c,Quote__c, Requested_Delivery_Date__c, OrderNum__c
                                        From Sales_Order__c Where Quote__c IN: OppSet]){
           mapSo.put(SO.Quote__c,SO); 
        }
        for(Opportunity oop : OppForPercentage){
            if(oop.Id == Oldmap.get(oop.Id).Id){
                if(oop.Probability != OldMap.get(oop.Id).Probability){
                    mapSo.get(oop.Id).Quote_Odds__c  = oop.Probability;
                    SoToUpdate.put(mapso.get(oop.id).Id, mapso.get(oop.id));
	                    
                }
                
            }
            if(Oop.CloseDate != Oldmap.get(Oop.Id).CloseDate){
                mapso.get(oop.Id).Requested_Delivery_Date__c = Oop.CloseDate;
                SoToUpdate.put(mapso.get(oop.id).Id, mapso.get(oop.Id));
            }
            if(Oop.StageName != OldMap.get(oop.Id).StageName){
                if(Oop.StageName == 'Closed Lost'){
                    if(!((mapso.get(oop.Id).OrderNum__c != null) && (mapso.get(oop.Id).OrderNum__c.charAt(0) == 67 || mapso.get(oop.Id).OrderNum__c.charAt(0) ==99))){
                        mapso.get(oop.Id).OrderNum__c = 'Quote Lost';
                        SoToUpdate.put(mapso.get(oop.Id).Id,mapso.get(oop.Id));
                    }
                }
            }
            
        }
        Update SoToUpdate.values();
        
    }

 
Hi Guys ! i am getting too many dml statements error by using this code i know the problem that is i am using a dml statement inside a loop but i dnt know how to do it out side loop because i need the product id for pricebook entry is there a way to do it  
  for (SalesLine__c SL : SlList){
           if(SL.Product__c == null && SL.Unit_Price__c != null){
               
             Product2 Prod = new Product2( Name = SL.Description__c,
                ProductCode = SL.No__c + ForName.get(Sl.Sales_Order__c),
                IsActive= True,
                Product_Type__c = 'Charge(item)');
               Insert Prod;
               system.debug('Updating' + SL);
               
               PricebookEntry pbe = new PricebookEntry(
                        Product2Id = Prod.Id,
                        UnitPrice = SL.Unit_Price__c,
                        Pricebook2Id = pb.Id,
                        IsActive = TRUE);
               
           LinesToUpdate.add(new SalesLine__c(Id=SL.Id,Product__c = prod.Id,Sales_Order__c = SL.Sales_Order__c));  
          // ProductsToAdd.add(Prod);
           PbeToAdd.add(pbe);
           
           }
           
       }
        //Insert ProductsToAdd;
        Insert PbeToAdd;
        Update LinesToUpdate;
        
Hi guys ! i am going through every opportunity to copy records from another object  Here is my code 
List<OpportunityLineItem> result = new List<OpportunityLineItem>();
            List<PricebookEntry> pbe  = [SELECT Id, Product2Id, IsActive FROM PricebookEntry WHERE Product2Id IN :ProductIds];
               
                for (Opportunity op : opps){
                List<OpportunityLineItem> oli = [SELECT OpportunityId FROM OpportunityLineItem WHERE OpportunityId =: op.Id];
                   if(oli.size() == 0){
                     for(Sales_Order__c s :so){
                      	for(PricebookEntry pbee : pbe){
                     		for(SalesLine__c SL : productIdToSLineMap.get(pbee.Product2Id)){
                         		if(op.Id == s.Quote__c && SL.Sales_Order__c == s.Id){
                                    result.add (new OpportunityLineItem(
                                    OpportunityId = SL.Opportunity_Id__c,
                                    PricebookEntryId = pbee.Id,
                                    Quantity = SL.Quantity__c > 0 ? SL.Quantity__c : 1,
                                    UnitPrice =(SL.Quantity__c > 0 ? (SL.Amount__c > 0 ? SL.Amount__c/SL.Quantity__c : 0) : (SL.Amount__c > 0 ? SL.Amount__c : 0)))) ;
                          }
                        }
                      }
                   }
                   }else{
                       system.debug('OpportunityLineItem Exists');
                   }
             }
         insert result;

This gives too many soql error because i am checking if there are opportunitylineitems in opportunity in a loop is there a way to do this without querying in a loop  any help would be appreciated
Hello ! i am developing this code to delete tasks from previous opportunity's the problem in this code is this gives too many soql error because i have 1000's of opportunity's to work is there a way i can do this i mean can i delete tasks from opportunity's based on lastmodified date or all at once please help 
global class SalesOrderOpportunityTasks implements Schedulable{
    
    global static String CRON_EXP = '0 0 8 * * ? *'; 

    global void execute(SchedulableContext sc)
    {
        doOpportunityUpdates();
    }
    global void doOpportunityUpdates()
    {
          List<Opportunity> opps = [Select Id,StageName,Name From Opportunity Where LastModifiedDate > = 2015-11-27T00:00:00Z and LastModifiedDate < = 2015-12-01T00:00:00Z Limit 33];
          List<Sales_Order__c> so = new List<Sales_Order__c>();
        for (Opportunity o : opps)
        {
        System.debug('Debug Opportunity :' + o.Id +'----' + o.Name);
            so = [SELECT Id,OrderNum__c,Quote__c FROM Sales_Order__c WHERE Quote__c = :o.Id];
        }
        for(Sales_Order__c s :so)
            {
                if(s.OrderNum__c != Null)
                {
                 if(s.OrderNum__c == 'QUOTE WON' || s.OrderNum__c == 'QUOTE LOST' || s.OrderNum__c.charAt(0) == 67 || s.OrderNum__c.charAt(0) == 99)
                 {
                    
                    List<Task> deleteTasks = [SELECT Id, Type, Status, WhatId FROM Task WHERE WhatId = :s.Quote__c];
                    System.debug('Deug Tasks' +deleteTasks);
                    System.debug(s.Quote__c);
                  if(!deleteTasks.isEmpty())
                  {
                    System.debug('Mon'  + deleteTasks);
                    delete deleteTasks;
                    }
                    
                 }
                }
                
            }
        
        
        
    }
    

}

 
Hi Guys, 
My orders are not showing in my opportunity(see image 1 ) and the opportunity field is not showing when creating an order through opportunity(See image 2 ) i have added the field in page layout but its still not showing What to do ?? Need Help  [Salesorder in Opportunity]


User-added image

User-added image
Hi Guys, 
My orders are not showing in my opportunity(see image 1 ) and the opportunity field is not showing when creating an order through opportunity(See image 2 ) i have added the field in page layout but its still not showing What to do ?? Need Help Salesorder in Opportunity


Creating a new order
This code is not covered by my test class how do i invoke this ?                   
if (hasProfilePic) {
                        if ( profilePicture.BodyLength > 0 ) {
                            if (profilePicture.Name.toLowerCase().endsWith('.png') || profilePicture.Name.toLowerCase().endsWith('.bmp') || profilePicture.Name.toLowerCase().endsWith('.jpg') || profilePicture.Name.toLowerCase().endsWith('.jpeg')) {
                                if (profilePicture.BodyLength <= 307200) {
                                    if ( Pattern.matches('(0?[1-9]|[12][0-9]|3[01])/(0?[1-9]|1[012])/((19|20)\\d\\d)', fieldDOB)) {
                                        Account v_newAccount = new Account(Id = currentAccount.Id, 
                                                           Suffix__c = fieldsuffix,
                                                           BillingCountry = fieldcountry,
                                                           Snowboarding_ab_level__c = fieldsnowboarding, 
                                                           Mountain_Biking_ab_level__c = fieldmountainbiking ,
                                                           PersonEmail = fieldPersonEmail,
                                                           FirstName = fieldfirstname,
                                                           LastName = fieldlastname,
                                                           Salutation = fieldtitle,
                                                           EmergencyName__c = fieldEmergencyName,
                                                           EmergencyNumber__c = fieldEmergencyNumber,
                                                           AbLevel__c = fieldAbLevel,
                                                           ClientCitizen__c =fieldClientCitizen,
                                                           ClientEmail__c = fieldClientEmail,
                                                           DOB__c = Date.parse(fieldDOB),
                                                           Phone = fieldPhone,
                                                           BillingStreet = fieldStreet,
                                                           BillingCity = fieldCity,
                                                           BillingState = fieldState,
                                                           BillingPostalCode = fieldPostalCode,
                                                           Special_Requests__c = fieldRequests,
                                                           Special_Dietary_Concerns__c = fieldDietary,
                                                           Special_Medical_Concerns__c = fieldMedical,
                                                           Snowcat_Downhill__c = v_Snowcat_Downhill,
                                                           Gender__c = fieldGender,
                                                           Favorite_Drink__c = this.fieldFavoriteDrink,
                                                           Favorite_Retallack_Experience__c = this.fieldFavoriteRetallackExperience,
                                                           Preferred_Guide_Driver__c = fieldPreferedGuideDriver);
                                        
                                        update v_newAccount;
                                        editData = false;
                                        //Current Account
                                        currentAccount = [
                                                SELECT Salutation,Mountain_Biking_ab_level__c,Snowboarding_ab_level__c,FirstName,LastName,EmergencyName__c,EmergencyNumber__c,AbLevel__c,ClientCitizen__c,ClientEmail__c,DOB__c, PersonEmail, Phone, IsPersonAccount,
                                                       BillingStreet, BillingCity, Gender__c, Preferred_Guide_Driver__c,
                                                       BillingState, BillingPostalCode,
                                                       Special_Requests__c, Special_Dietary_Concerns__c,
                                                       Special_Medical_Concerns__c, Snowcat_Downhill__c,
                                                       Favorite_Drink__c, Favorite_Retallack_Experience__c
                                                FROM Account
                                                WHERE Id  = :currentOpp.AccountId];
                                        firstPaymentCheckbox = false;
                                        secondPaymentCheckbox = false;
                                        if (profilePicture.BodyLength > 0) {
                                            // delete existing avatars
                                            delete [SELECT Id FROM Attachment WHERE Name LIKE 'ProfilePic_%' AND ParentId = :currentAccount.Id];
                                            // insert new avatar
                                            profilePicture.Name = 'ProfilePic_'+profilePicture.Name;
                                            insert profilePicture;
                                            hasProfilePic = TRUE;
                                            curProfilePictureId = profilePicture.Id;
                                        }
                                    } else {
                                        ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, ' Incorrect date. '));
                                    }
                                } else {
                                    ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, ' File size can not exceed 300kb. '));
                                }
                            } else {
                                ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, ' Only .jpeg, .jpg, .png, .bmp extensions supported. '));
                            }
 
Hi,
i have a process in process builder which changes the field (Status -- > picklist) (Market -- > picklist)

If Status changes to Budget we change Market to Budget
If Market changes to Budget we change Status to Budget. 
and its going recursive how do i stop that 
 
Hi guys ! i am going through every opportunity to copy records from another object  Here is my code 
List<OpportunityLineItem> result = new List<OpportunityLineItem>();
            List<PricebookEntry> pbe  = [SELECT Id, Product2Id, IsActive FROM PricebookEntry WHERE Product2Id IN :ProductIds];
               
                for (Opportunity op : opps){
                List<OpportunityLineItem> oli = [SELECT OpportunityId FROM OpportunityLineItem WHERE OpportunityId =: op.Id];
                   if(oli.size() == 0){
                     for(Sales_Order__c s :so){
                      	for(PricebookEntry pbee : pbe){
                     		for(SalesLine__c SL : productIdToSLineMap.get(pbee.Product2Id)){
                         		if(op.Id == s.Quote__c && SL.Sales_Order__c == s.Id){
                                    result.add (new OpportunityLineItem(
                                    OpportunityId = SL.Opportunity_Id__c,
                                    PricebookEntryId = pbee.Id,
                                    Quantity = SL.Quantity__c > 0 ? SL.Quantity__c : 1,
                                    UnitPrice =(SL.Quantity__c > 0 ? (SL.Amount__c > 0 ? SL.Amount__c/SL.Quantity__c : 0) : (SL.Amount__c > 0 ? SL.Amount__c : 0)))) ;
                          }
                        }
                      }
                   }
                   }else{
                       system.debug('OpportunityLineItem Exists');
                   }
             }
         insert result;

This gives too many soql error because i am checking if there are opportunitylineitems in opportunity in a loop is there a way to do this without querying in a loop  any help would be appreciated
Hello ! i am developing this code to delete tasks from previous opportunity's the problem in this code is this gives too many soql error because i have 1000's of opportunity's to work is there a way i can do this i mean can i delete tasks from opportunity's based on lastmodified date or all at once please help 
global class SalesOrderOpportunityTasks implements Schedulable{
    
    global static String CRON_EXP = '0 0 8 * * ? *'; 

    global void execute(SchedulableContext sc)
    {
        doOpportunityUpdates();
    }
    global void doOpportunityUpdates()
    {
          List<Opportunity> opps = [Select Id,StageName,Name From Opportunity Where LastModifiedDate > = 2015-11-27T00:00:00Z and LastModifiedDate < = 2015-12-01T00:00:00Z Limit 33];
          List<Sales_Order__c> so = new List<Sales_Order__c>();
        for (Opportunity o : opps)
        {
        System.debug('Debug Opportunity :' + o.Id +'----' + o.Name);
            so = [SELECT Id,OrderNum__c,Quote__c FROM Sales_Order__c WHERE Quote__c = :o.Id];
        }
        for(Sales_Order__c s :so)
            {
                if(s.OrderNum__c != Null)
                {
                 if(s.OrderNum__c == 'QUOTE WON' || s.OrderNum__c == 'QUOTE LOST' || s.OrderNum__c.charAt(0) == 67 || s.OrderNum__c.charAt(0) == 99)
                 {
                    
                    List<Task> deleteTasks = [SELECT Id, Type, Status, WhatId FROM Task WHERE WhatId = :s.Quote__c];
                    System.debug('Deug Tasks' +deleteTasks);
                    System.debug(s.Quote__c);
                  if(!deleteTasks.isEmpty())
                  {
                    System.debug('Mon'  + deleteTasks);
                    delete deleteTasks;
                    }
                    
                 }
                }
                
            }
        
        
        
    }
    

}

 
Hi Guys, 
My orders are not showing in my opportunity(see image 1 ) and the opportunity field is not showing when creating an order through opportunity(See image 2 ) i have added the field in page layout but its still not showing What to do ?? Need Help  [Salesorder in Opportunity]


User-added image

User-added image