+ Start a Discussion

S2S Sharing Opportunity Products

Hello, I have Salesforce to Salesforce setup and I'm trying to share opportunity records and opportunity products with the target org. We want to be able to manually share the opportunity record with by using the standard external sharing button with S2S. However, we would like to automatically send over opportunity products on any opportunities that we are sharing between the two orgs. Below is the code that I have to try to automatically send over the opp producst but it's not inserting or updating in the target org. Any assistance is appreciated. Thank you. 

public class S2SForward {
       public S2SForward(){
        List<PartnerNetworkRecordConnection> oppProds = new  List<PartnerNetworkRecordConnection>();
    public static void upsertOLI(List<SObject> oliList){
    List <PartnerNetworkRecordConnection> prncList = new List <PartnerNetworkRecordConnection>();
	List <PartnerNetworkConnection> connectionList = new List <PartnerNetworkConnection>([Select Id, ConnectionStatus, ConnectionName from PartnerNetworkConnection where ConnectionStatus = 'Accepted' AND Id = '04P3i000000004OEAQ']);
	Map <ID, PartnerNetworkConnection> connMap = new Map<ID, PartnerNetworkConnection>([Select Id, ConnectionStatus, ConnectionName from PartnerNetworkConnection where ConnectionStatus = 'Accepted' AND Id = '04P1Q000000CaoyUAC']);
	Map <ID, ID> oppIdvsOLIIdMap = new Map<Id, Id>();
	Map<ID, Opportunity> oppWithOppLineItemMap;
    List<Opportunity> oppList = new List<Opportunity>();
    List<OpportunityLineItem> oppLI = new List<OpportunityLineItem>();
    Id cid;
    String status;
    String connectionName;
    for(ID connId :connMap.keySet()){
			cid = connMap.get(connId).ID;
            status = connMap.get(connId).ConnectionStatus;
            connectionName = connMap.get(connId).ConnectionName;
        //Populate a map of Opp Ids and OppLineItems
        for(OpportunityLineItem oppLineRecord: oppLI){
            if(oppLineRecord.Id == '00k1Q00003ZzlgO' ){
               oppIdvsOLIIdMap.put(oppLineRecord.ID, oppLineRecord.OpportunityId);
        if(oppIdvsOLIIdMap.keyset().size() > 0){
            for(Id oppId:oppIdvsOLIIdMap.keyset() ){
                Id opportunityId = oppIdvsOLIIdMap.get(oppId);
                prncList.add(new PartnerNetworkRecordConnection(
                ConnectionId = '04P1Q000000CaoyUAC',
                LocalRecordId = '04P3i000000004OEAQ',
                ParentRecordId = '0061Q00000oj1Dk',
                RelatedRecords = 'OpportunityLineItem'  
            //    prncList.add(newRecord);
    for(PartnerNetworkConnection network: connectionList){
      Opportunity o = new Opportunity();
      PartnerNetworkRecordConnection newrecord = new PartnerNetworkRecordConnection();
      newRecord.ConnectionId = network.Id;
      newRecord.LocalRecordId = '0061Q00000oj1Dk';
      newRecord.ParentRecordId = '0061Q00000oj1Dk';
      newRecord.RelatedRecords = 'OpportunityLineItem';   
        upsert prncList;



trigger S2SShareOppProds on OpportunityLineItem (after insert, after update) {
    if(Trigger.isAfter && (Trigger.isInsert || Trigger.isUpdate)){