• Sam Wilson 16
  • NEWBIE
  • 15 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 2
    Replies
We have a custom object called Feedback that has lookups to both Contacts and Opportunities. Feedback records are created from Opportunities using a custom button URL hack.

The custom button populates the Opportunity lookup and Date fields on a new Feedback record but won't populate the Contact lookup.

The Contact entry should be coming from the custom lookup field on Opportunities called Primary Contact (which is auto-populated with the Primary Contact Role using flows).

My custom button URL is
/a0V/e? 
CF00N6E000000h3Cz={!Opportunity.Primary_Contact__c}
&CF00N6E000000h3Cz_lkid={!Opportunity.Primary_ContactId__c} 
&00N6E000000h2HU={!TODAY()} 
&CF00N6E000000h2ID={!Opportunity.Name} 
&CF00N6E000000h2ID_lkid={!Opportunity.Id} 
&retURL=%2F{!Opportunity.Id}

Any help would be greatly appreciated!
Hi,

We are using the Opportunity Products to Assets app (https://appexchange.salesforce.com/listingDetail?listingId=a0N30000001yKgpEAE) to create assets from opportunity products on closed/won opportunities. I am looking to amend the Apex Trigger component that passes the Account ID from the Opportunity to the Asset.

Our business is a broker, so we have 2 account record types that are attached to an opportunity. The customer account owns the opportunity but we then attach a partner/supplier account to the opportunity product via a custom lookup field. The above app passes the account that owns the opportunity ( the customer in our case) to the asset. We instead would like the partner account ID from the opportunity product (named Operator__c in our org) to be passed over as the owner of the asset.

Below is the standard component from the app with my amendments in bold. I have amended the Account.Id = portion of the below component to reference the opportunity line item Operator__c field but it is not working. I receive the following error –

 
Error: Compile Error: Invalid foreign key relationship: OpportunityLineItem.Operator__c
 
Any help would be much appreciated!


trigger CreateAssetonClosedWon on Opportunity (after insert, after update) {
     for(Opportunity o: trigger.new){ 
      if(o.isWon == true && o.HasOpportunityLineItem == true){
         String opptyId = o.Id;
         OpportunityLineItem[] OLI = [Select 
Operator__c, UnitPrice, Quantity, PricebookEntry.Product2Id, PricebookEntry.Product2.Name, Description, Converted_to_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 = ol.Operator__c.Id;
            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;
            ast.add(a);
            ol.Converted_to_Asset__c = true;
       }
      update OLI; 
      insert ast;
     }
    }
}

 
 
We have a custom object called Feedback that has lookups to both Contacts and Opportunities. Feedback records are created from Opportunities using a custom button URL hack.

The custom button populates the Opportunity lookup and Date fields on a new Feedback record but won't populate the Contact lookup.

The Contact entry should be coming from the custom lookup field on Opportunities called Primary Contact (which is auto-populated with the Primary Contact Role using flows).

My custom button URL is
/a0V/e? 
CF00N6E000000h3Cz={!Opportunity.Primary_Contact__c}
&CF00N6E000000h3Cz_lkid={!Opportunity.Primary_ContactId__c} 
&00N6E000000h2HU={!TODAY()} 
&CF00N6E000000h2ID={!Opportunity.Name} 
&CF00N6E000000h2ID_lkid={!Opportunity.Id} 
&retURL=%2F{!Opportunity.Id}

Any help would be greatly appreciated!
Hi,

We are using the Opportunity Products to Assets app (https://appexchange.salesforce.com/listingDetail?listingId=a0N30000001yKgpEAE) to create assets from opportunity products on closed/won opportunities. I am looking to amend the Apex Trigger component that passes the Account ID from the Opportunity to the Asset.

Our business is a broker, so we have 2 account record types that are attached to an opportunity. The customer account owns the opportunity but we then attach a partner/supplier account to the opportunity product via a custom lookup field. The above app passes the account that owns the opportunity ( the customer in our case) to the asset. We instead would like the partner account ID from the opportunity product (named Operator__c in our org) to be passed over as the owner of the asset.

Below is the standard component from the app with my amendments in bold. I have amended the Account.Id = portion of the below component to reference the opportunity line item Operator__c field but it is not working. I receive the following error –

 
Error: Compile Error: Invalid foreign key relationship: OpportunityLineItem.Operator__c
 
Any help would be much appreciated!


trigger CreateAssetonClosedWon on Opportunity (after insert, after update) {
     for(Opportunity o: trigger.new){ 
      if(o.isWon == true && o.HasOpportunityLineItem == true){
         String opptyId = o.Id;
         OpportunityLineItem[] OLI = [Select 
Operator__c, UnitPrice, Quantity, PricebookEntry.Product2Id, PricebookEntry.Product2.Name, Description, Converted_to_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 = ol.Operator__c.Id;
            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;
            ast.add(a);
            ol.Converted_to_Asset__c = true;
       }
      update OLI; 
      insert ast;
     }
    }
}