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
Siva SakthiSiva Sakthi 

salesforce to salesforce connection record sharing for auto accept

Hi
       I have created the trigger for automatically inserted the records form source to destination org with connection.Its not automatically inserted in the main object except we have to accept manually.Its stored in the Connection Section after click the go button in this section its show all records from the source org. we can accept manually one by one and give required relationship field. I have checked that in Subscribed objection section to enable the 'auto accept' option but its unable to choose. It will show the below message
Msg: Auto-accept isn't available for child objects, like opportunity products and tasks, because child records are automatically accepted with their parent record. 
We have checked the OWD also all are provided as Public Read/Write option.

I have created the trigger for before insert the relationship field mapping like fromula to text field mentioned inthe connection process. But its not working. Could you please anyone help me to provide solution for auto accept of records.Please find the screen shot & coding. Help me how to solve this issue. Where i made mistake.

Thanks
Siva
Marks record from connection 
 
Example Trigger Code :
==================
trigger MarksTrigger on Marks__c (before insert, before update) {
   
    List<String> StuMark = new List<String>(); 
    for (Marks__c sm : Trigger.new) {
           StuMark.add(sm.Stu_Course_Plan__c); 
    }  

    List <Course_Plan__c> SCPList=[Select Id, Name from Course_Plan__c Where Name IN:StuMark];
    Map <String,Id> smMap= new Map<String,Id>();
    for(Course_Plan__c scp:SCPList) {
        smMap.put(scp.Name,scp.Id);
    } 
             
    for (Marks__c smadd : Trigger.new)  {

        if (!smMap.isEmpty() && smadd.Course__c == null) {
                smadd.Course__c = smMap.get(smadd.Stu_Course_Plan__c);               
        }   
    }

    /* Another way i tried to map the relationship field */
   
   /* for(Marks__c sm : trigger.new) {                
        Course_Plan__c scp = [select Id, Name from Course_Plan__c where Name = :sm.Stu_Course_Plan__c limit 1 ];
        system.debug('Trigeer SCP Id ====== :: '+ sm.Stu_Course_Plan__c );
        system.debug('Trigger MarkId ====== :: '+ scp.Name);
        sm.Course__c = scp.Name;
    }  */    
    
}