• kalai siva 8
  • NEWBIE
  • 0 Points
  • Member since 2016
  • avon

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 5
    Replies
share opportunity line items salesforce to salesforce
triggers to share opportunity line items salesforce to salesforce
share opportunity line items salesforce to salesforce
triggers to share opportunity line items salesforce to salesforce

Hi,

 

I've successfully written a trigger to automatically share Account records with related opportunities to partners.  I've written a second trigger on Opportunities that does the same thing.  This is so that once an account is shared, new opportunities also get shared.

 

The problem is now Opportunity Line Items.   After much fooling around, I've finally got it all configured nicely so that I can share opportunities and opportunity line items manually through the Salesforce UI and the product lines land nicely in the partner system.  However I want to do this by trigger as well, so that not just the opportunity goes, but also the line items.  I feel that if it works manually, the trigger should work but it doesnt.

 

Here's the trigger.  Any ideas??

 

Thanks!!

 

 

trigger shareOpportunity on Opportunity (after insert, after update) {

List<PartnerNetworkConnection> connMap = new List<PartnerNetworkConnection>([select Id, 
    ConnectionStatus, ConnectionName from PartnerNetworkConnection where ConnectionStatus = 'Accepted']);

List<PartnerNetworkRecordConnection> pncList = new List<PartnerNetworkRecordConnection>();



    for (Opportunity o : Trigger.new) {
        if (o.Originating_System__c == 'CRR' ) {
            for (PartnerNetworkConnection pnc : connMap) {
                
             PartnerNetworkRecordConnection newOpprecord = new PartnerNetworkRecordConnection(
                
                        ConnectionId = pnc.Id,
                        LocalRecordId = o.Id,
                        SendClosedTasks = false,
                        SendOpenTasks = false,
                        SendEmails = false,
                        ParentRecordId = o.AccountId,
                        RelatedRecords = 'OpportunityLineItem'
                    );
                        
                pncList.add(newOpprecord);
                
            }   
        }
    }
    
    
    
    if (!pncList.isEmpty()) {
        upsert pncList;
    }

 

}