Skip to main content
Tweeted twitter.com/#!/StackSalesforce/status/492833039459041281
edited title
Link

Create Record (CObject) from OpportunityItemListOpportunityLineItem when Opportunity is Closed Won

Source Link

Create Record (CObject) from OpportunityItemList when Opportunity is Closed Won

I'm trying to create a record of each item in the Opportunity when an Opportunity is Closed Won.

OpportunityItemList:

  • Date (Date)
  • Product2 Lookup(Product)
  • ExpiryDate__c (Date)
  • ServiceNumber__c Text(30)
  • Opportunity Lookup(Opportunity)

Membership__c

  • AccountName__c Lookup(Account)
  • ExpiryDate__c (Date)
  • IssuedDate__c (Date)
  • OpportunityName__c Lookup(Opportunity)
  • ServiceName__c Lookup(Product)

I'm using this trigger but I get blank info in the Lookup fields...

trigger CreateMembership on OpportunityLineItem (after update) {

    List<Membership__c> comms = new List<Membership__c>(); 

    for(OpportunityLineItem a : trigger.new) {   
            
            Membership__c comm = new Membership__c();
           
            comm.Name = a.ServiceNumber__c; 
           
            comm.AccountName__c = a.Opportunity.AccountId; 
            comm.OpportunityName__c = a.OpportunityId; 
            comm.ServiceName__c = a.PricebookEntry.Product2Id;  
           
            comm.Stage__c = 'Active'; 
            comm.IssuedDate__c = a.ServiceDate;
            comm.ExpiryDate__c = a.ExpiryDate__c;
           
            comms.add(comm);    
    
    }

    insert comms; 

}