• Atomic_Force
  • NEWBIE
  • 0 Points
  • Member since 2012

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 3
    Replies

Need to update a custom boolean field on Product2 if PricebookEntry UnitPrice > 0.  Here is the simple trigger that I started to update the value of Product2 In_Pricelist__c field.  How do I get this portion of the trigger to work and then iterate over PricebookEnties to see if Product2Id is in list and UnitPrice > 0?

trigger trueInPricelist on Product2 (before update) {
   
   List<Product2> prods2update = new list<Product2>();
   
        for(Product2 prods : trigger.new){
            if(prods.In_Pricelist__c == Null){
                prods2update.add(prods);
        }
        if(prods2update.size() > 0){
        	for (Product2 p : prods2update){
        		p.In_Pricelist__c = True;
        		    
        }
        }
        update prods2update;
        }
}

 

Really need some help!  I created a Trigger that inserts records into a custom object.  The after insert is working.  However, the trigger just keeps inserting records.  Need help with the after update part.  How do I use Old.map New.Map in this trigger?  OppShipMonthAssociation__c is a junction object.  Ship_Month__c is a custom object.  Code is below:

 

trigger insertOppShipMoAssoc on Opportunity (after insert, after update) {
	List<OppShipMonthAssociation__c> osmas = new List<OppShipMonthAssociation__c>();
    for (Opportunity newOpportunity: Trigger.New) {
    	for (integer i = 0; i < newOpportunity.Number_of_Ship_Months__c; i++ ) {
            if(newOpportunity.Book_Ship_in_QTR__c == 'Yes' && newOpportunity.ForecastCategoryName == 'Commit') {
                Osmas.add(new OppShipMonthAssociation__c(
                        Name = newOpportunity.Id,
                    	Opportunity__c = newOpportunity.Id,
                		Ship_Month__c = ));
                
                
            }
		}
		 insert Osmas;
	}
}

 

Need to update a custom boolean field on Product2 if PricebookEntry UnitPrice > 0.  Here is the simple trigger that I started to update the value of Product2 In_Pricelist__c field.  How do I get this portion of the trigger to work and then iterate over PricebookEnties to see if Product2Id is in list and UnitPrice > 0?

trigger trueInPricelist on Product2 (before update) {
   
   List<Product2> prods2update = new list<Product2>();
   
        for(Product2 prods : trigger.new){
            if(prods.In_Pricelist__c == Null){
                prods2update.add(prods);
        }
        if(prods2update.size() > 0){
        	for (Product2 p : prods2update){
        		p.In_Pricelist__c = True;
        		    
        }
        }
        update prods2update;
        }
}

 

Really need some help!  I created a Trigger that inserts records into a custom object.  The after insert is working.  However, the trigger just keeps inserting records.  Need help with the after update part.  How do I use Old.map New.Map in this trigger?  OppShipMonthAssociation__c is a junction object.  Ship_Month__c is a custom object.  Code is below:

 

trigger insertOppShipMoAssoc on Opportunity (after insert, after update) {
	List<OppShipMonthAssociation__c> osmas = new List<OppShipMonthAssociation__c>();
    for (Opportunity newOpportunity: Trigger.New) {
    	for (integer i = 0; i < newOpportunity.Number_of_Ship_Months__c; i++ ) {
            if(newOpportunity.Book_Ship_in_QTR__c == 'Yes' && newOpportunity.ForecastCategoryName == 'Commit') {
                Osmas.add(new OppShipMonthAssociation__c(
                        Name = newOpportunity.Id,
                    	Opportunity__c = newOpportunity.Id,
                		Ship_Month__c = ));
                
                
            }
		}
		 insert Osmas;
	}
}