Skip to main content
added 27 characters in body
Source Link
user48169
user48169

I have been trying to create this trigger and its not working. I'm not getting any errors, but an opportunity product is not being added to the opportunity automatically. I'm not sure why.

Here is the code:

trigger AUTOADDPRODUCTAttempt1 on OpportunityLineItem (after insert) {
    List<OpportunityLineItem> OpportunityLineItems = new List<OpportunityLineItem>(); 
    for (OpportunityLineItem newOpportunityLineItemsitem: Trigger.New)[
 {  SELECT OpportunityId, Name 
   FROM OpportunityLineItem
   WHERE if(newOpportunityLineItemsId = :Trigger.new AND Name === 'CarOIL''Car_Filter_Plus']) {
            OpportunityLineItems.add(new OpportunityLineItem(PricebookEntryId 
 ='ID CODE FOR CarOILplus',Quantity = 1,UnitPrice      OpportunityId = 25));item.OpportunityId, 
        }
    }PricebookEntryId ='01uA000000QdelEIAD',
    if(!OpportunityLineItems.isEmpty()){        Quantity = 1,
        insert OpportunityLineItems;   UnitPrice = 25)
        );
}
}

Ideally, here is what I need the code to do:

We have a lot of additional cost products that need to be be added to the opportunity whenever a product is added to the opportunity by the proposal team. The $ value of the additional cost needs to be a % of the product added by the proposal writer. I came across a couple codes online but have not been able to get very far. Here is one that I came across:

Proposal writer adds the following products

  • CarOIL
  • CarFILTER
  • CarTIRE'
  • CarLIGHTS

The $ value is manually added by the writer in SFDC. They put the quantity and sale price and it auto calculates

Here is what I need the code to automatically add to the opportunity

  • CarOILplus
  • CarFILTERplus
  • CarTIREplus
  • CarLIGHTSplus

The $ value of each plus product is a % of the original product, which has a dollar value entered by the writer. For example:

CarOILplus - is 5% of the $ value entered by the write when added CarOIL CarFILTERplus - is 2% of the $ value entered by the write when added CarFILTER CarTIREplus - is 3% of the $ value entered by the write when added CarTIRE CarLIGHTplus - is 1% of the $ value entered by the write when added CarLIGHT Can anyone help me? Please...

I have been trying to create this trigger and its not working. I'm not getting any errors, but an opportunity product is not being added to the opportunity automatically. I'm not sure why.

Here is the code:

trigger AUTOADDPRODUCT on OpportunityLineItem (after insert) {
    List<OpportunityLineItem> OpportunityLineItems = new List<OpportunityLineItem>(); 
    for (OpportunityLineItem newOpportunityLineItems: Trigger.New) { 
        if(newOpportunityLineItems.Name == 'CarOIL'){
            OpportunityLineItems.add(new OpportunityLineItem(PricebookEntryId ='ID CODE FOR CarOILplus',Quantity = 1,UnitPrice = 25));
        }
    } 
    if(!OpportunityLineItems.isEmpty()){
        insert OpportunityLineItems; 
    }
}

Ideally, here is what I need the code to do:

We have a lot of additional cost products that need to be be added to the opportunity whenever a product is added to the opportunity by the proposal team. The $ value of the additional cost needs to be a % of the product added by the proposal writer. I came across a couple codes online but have not been able to get very far. Here is one that I came across:

Proposal writer adds the following products

  • CarOIL
  • CarFILTER
  • CarTIRE'
  • CarLIGHTS

The $ value is manually added by the writer in SFDC. They put the quantity and sale price and it auto calculates

Here is what I need the code to automatically add to the opportunity

  • CarOILplus
  • CarFILTERplus
  • CarTIREplus
  • CarLIGHTSplus

The $ value of each plus product is a % of the original product, which has a dollar value entered by the writer. For example:

CarOILplus - is 5% of the $ value entered by the write when added CarOIL CarFILTERplus - is 2% of the $ value entered by the write when added CarFILTER CarTIREplus - is 3% of the $ value entered by the write when added CarTIRE CarLIGHTplus - is 1% of the $ value entered by the write when added CarLIGHT Can anyone help me? Please...

I have been trying to create this trigger and its not working. I'm not getting any errors, but an opportunity product is not being added to the opportunity automatically. I'm not sure why.

Here is the code:

trigger Attempt1 on OpportunityLineItem (after insert) {
    List<OpportunityLineItem> OpportunityLineItems = new List<OpportunityLineItem>(); 
for(OpportunityLineItem item: [
   SELECT OpportunityId, Name 
   FROM OpportunityLineItem
   WHERE Id = :Trigger.new AND Name = 'Car_Filter_Plus']) {
        OpportunityLineItems.add(new OpportunityLineItem( 
            OpportunityId = item.OpportunityId, 
            PricebookEntryId ='01uA000000QdelEIAD',
            Quantity = 1,
            UnitPrice = 25)
        );
}
}

Ideally, here is what I need the code to do:

We have a lot of additional cost products that need to be be added to the opportunity whenever a product is added to the opportunity by the proposal team. The $ value of the additional cost needs to be a % of the product added by the proposal writer. I came across a couple codes online but have not been able to get very far. Here is one that I came across:

Proposal writer adds the following products

  • CarOIL
  • CarFILTER
  • CarTIRE'
  • CarLIGHTS

The $ value is manually added by the writer in SFDC. They put the quantity and sale price and it auto calculates

Here is what I need the code to automatically add to the opportunity

  • CarOILplus
  • CarFILTERplus
  • CarTIREplus
  • CarLIGHTSplus

The $ value of each plus product is a % of the original product, which has a dollar value entered by the writer. For example:

CarOILplus - is 5% of the $ value entered by the write when added CarOIL CarFILTERplus - is 2% of the $ value entered by the write when added CarFILTER CarTIREplus - is 3% of the $ value entered by the write when added CarTIRE CarLIGHTplus - is 1% of the $ value entered by the write when added CarLIGHT Can anyone help me? Please...

Source Link
user48169
user48169

Trigger issue: Opportunity product is not being added automatically to the opportunity

I have been trying to create this trigger and its not working. I'm not getting any errors, but an opportunity product is not being added to the opportunity automatically. I'm not sure why.

Here is the code:

trigger AUTOADDPRODUCT on OpportunityLineItem (after insert) {
    List<OpportunityLineItem> OpportunityLineItems = new List<OpportunityLineItem>(); 
    for (OpportunityLineItem newOpportunityLineItems: Trigger.New) { 
        if(newOpportunityLineItems.Name == 'CarOIL'){
            OpportunityLineItems.add(new OpportunityLineItem(PricebookEntryId ='ID CODE FOR CarOILplus',Quantity = 1,UnitPrice = 25));
        }
    } 
    if(!OpportunityLineItems.isEmpty()){
        insert OpportunityLineItems; 
    }
}

Ideally, here is what I need the code to do:

We have a lot of additional cost products that need to be be added to the opportunity whenever a product is added to the opportunity by the proposal team. The $ value of the additional cost needs to be a % of the product added by the proposal writer. I came across a couple codes online but have not been able to get very far. Here is one that I came across:

Proposal writer adds the following products

  • CarOIL
  • CarFILTER
  • CarTIRE'
  • CarLIGHTS

The $ value is manually added by the writer in SFDC. They put the quantity and sale price and it auto calculates

Here is what I need the code to automatically add to the opportunity

  • CarOILplus
  • CarFILTERplus
  • CarTIREplus
  • CarLIGHTSplus

The $ value of each plus product is a % of the original product, which has a dollar value entered by the writer. For example:

CarOILplus - is 5% of the $ value entered by the write when added CarOIL CarFILTERplus - is 2% of the $ value entered by the write when added CarFILTER CarTIREplus - is 3% of the $ value entered by the write when added CarTIRE CarLIGHTplus - is 1% of the $ value entered by the write when added CarLIGHT Can anyone help me? Please...