• Vibhuti Sharma 3
  • NEWBIE
  • 0 Points
  • Member since 2016

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

Hi, 
I need help in finding a way to figure out if the opportunity products already exists in accounts assest. And if these opportunity producst exists for that account then I need to put a flag for them claasifying them as new, upsell or renewal. 

Any help on this would be appreciated. 

Hi, 
I need help in finding a way to figure out if the opportunity products already exists in accounts assest. And if these opportunity producst exists for that account then I need to put a flag for them claasifying them as new, upsell or renewal. 

Any help on this would be appreciated. 

I downloaded the APEX trigger to create assets from Opportunity Line Items. How can I then update the opportunity line items with the ID of the newly created Asset? Any help is appreciated!

trigger CreateAssetonClosedWon on Opportunity (after insert, after update) {
     for(Opportunity o: trigger.new){ 
      if(o.isWon == true && o.HasOpportunityLineItem == true && o.type == 'Purchase'){
         String opptyId = o.Id;
         OpportunityLineItem[] OLI = [Select UnitPrice, Quantity, PricebookEntry.Product2Id, PricebookEntry.Product2.Name, Description, Converted_to_Asset__c, DOM__c, Asset__c  
                                      From OpportunityLineItem 
                                      where OpportunityId = :opptyId  and Converted_to_Asset__c = false];
         Asset[] ast = new Asset[]{};
         Asset a = new Asset();
         for(OpportunityLineItem ol: OLI){
            a = new Asset();
        a.AccountId = o.AccountId;
            a.Product2Id = ol.PricebookEntry.Product2Id;
            a.Quantity = ol.Quantity;
            a.Price =  ol.UnitPrice;
            a.PurchaseDate = o.CloseDate;
            a.Status = 'Purchased';
            a.Description = ol.Description;
            a.Name = ol.PricebookEntry.Product2.Name;
            a.Original_Opportunity__c = opptyID;
            a.In_Inventory__c = true;
            a.Date_of_Manufacturer__c = ol.DOM__c;
            ast.add(a);
            ol.Converted_to_Asset__c = true;
       }
      update OLI; 
      insert ast;
     }
    }
}