function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
ALAL 

Salesforce to Salesforce Auto-Accept Opportunities

I  have a salesforce to salesforce connection and I would like to be able to send both the opportunity and related opportunity products without having to manually accept them in the target org. According to salesforce documentation, if the auto-accept on opportunities is turned on, then opportunity products can't be shared. 

Is there a way to bypass this with an apex batch job perhaps (mass auto accept)?

Thank you
NagendraNagendra (Salesforce Developers) 
Hi Albert,

May I suggest you please check with below link from the success community which will point you in the right direction. Hope this helps.

Please mark this as solved if the information helps.

Thanks,
Nagendra
ALAL
Hello Nagendra thank you for your help. Below is the code I have, but I'm getting an error that says: List has more than 1 row for assignment to SObject. Do you know what the issue could be? Thanks 

trigger OppOwnerUpdate on Opportunity (after insert) {
 
   if(trigger.isinsert){

       //opportunity IDs needed to update the owner value. These id records are shared by published company
       set<id> FinalOptyIds = new set<id>();
 
       //Collect the  list of opties which are created/updated by partnernetwork companY
       List<PartnerNetworkRecordConnection> ConListOpty = new List<PartnerNetworkRecordConnection>(
                                       [select Id, ConnectionId, PartnerRecordId, LocalRecordId from PartnerNetworkRecordConnection
                                               where LocalRecordId in :Trigger.newmap.keyset() AND (Status ='Sent' OR Status = 'Received') AND ConnectionId='007499281']);
       //system.debug('ConListOpty-----' + ConListOpty);
 
       //Collect the opty ids
       if(!ConListOpty.isEmpty()){
           for(PartnerNetworkRecordConnection op : ConListOpty){
               if(op.LocalRecordId != null){
                          FinalOptyIds.add(op.LocalRecordId);
               }
           }
 
           system.debug('FinalOptyIds-----' + FinalOptyIds);
 
           // Query the available opties which are shared by partner network
           list<opportunity> optyList = [select id,owner.id from opportunity where id IN:FinalOptyIds];
 
           list<opportunity> optyListFinal = new list<opportunity>();
 
                     //TODO: Opportunity Owner Move this hardcoding id to custom settings. change for each org when deploying
         Opportunity oppOwner = [select id from Opportunity where OwnerID = '00520000003p1tO'];
           //system.debug('optyList-----' + optyList);
 
           for(opportunity optOwner: optyList ){
               if(optOwner.Ownerid != null){
                   opportunity opty = new opportunity();
                   opty.id = OptOwner.id;
                  opty.OwnerId = optOwner.id;
                 optOwner.id = '00520000003p1tO';
                   optyListFinal.add(optOwner);
                   //system.debug('Done----');
               }
           }
    
           //TODO: Move this hardcoding id to custom settings. change for each org when deploying
          Pricebook2 priceb = [select id from Pricebook2 where id = '341393019'];
           //system.debug('optyList-----' + optyList);
 
           //updating the shared created opty owners with Opportunity product
           for(opportunity opt: optyList ){
               if(opt.Pricebook2.id != null){
                   opportunity opty = new opportunity();
                   opty.id = opt.id;
                   opty.Pricebook2ID = opt.Pricebook2.id;
                   optyListFinal.add(opty);
                   //system.debug('Done----');
               }
           }
           update optyListFinal;
       }
 
}
}