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
goutham.tatineni1.3893010493585044E12goutham.tatineni1.3893010493585044E12 

Share primary Contacts along with the Opportunity using Sales Force to Sales Force Connector

Hi ,

Lead - gets converted to an Account , Contact and an Opportunity

I developed  a trigger which shares an Opportunity and realted Account with another Org of ours, and the peice i am missing is sharing the Contact along with this . Need some help for sharing the contact also.

Trigger autoforwardOpportunity on Opportunity(after insert) {
    String UserName = UserInfo.getName();
    String orgName = UserInfo.getOrganizationName();
    List<PartnerNetworkConnection> connMap = new List<PartnerNetworkConnection>(
        [select Id, ConnectionStatus, ConnectionName from PartnerNetworkConnection where ConnectionStatus = 'Accepted']
    );
    System.debug('Size of connection map: '+connMap.size());
    List<PartnerNetworkRecordConnection> prncList = new List<PartnerNetworkRecordConnection>();
    for(Integer i =0; i< Trigger.size; i++) {
        Opportunity acc = Trigger.new[i];
        String acId = acc.Id;
        System.debug('Value of OpportunityId: '+acId);
        for(PartnerNetworkConnection network : connMap) {
            String cid = network.Id;
            String status = network.ConnectionStatus;
            String connName = network.ConnectionName;
            String AssignedBusinessUnit = acc.Assigned_Business_Unit__c;
            System.debug('Connectin Details.......Cid:::'+cid+'Status:::'+Status+'ConnName:::'+connName+','+AssignedBusinessUnit);
            if(AssignedBusinessUnit!=Null && (AssignedBusinessUnit.equalsIgnoreCase('IT') || AssignedBusinessUnit.equalsIgnoreCase('Proservia'))) {    
                // Send account to IT instance
                PartnerNetworkRecordConnection newAccount = new PartnerNetworkRecordConnection();
                newAccount.ConnectionId = cid;
                newAccount.LocalRecordId = acc.AccountId;
                newAccount.SendClosedTasks = true;
                newAccount.SendOpenTasks = true;
                newAccount.SendEmails = true;
                newAccount.RelatedRecords = 'Contact';
                System.debug('Inserting New Record'+newAccount);
                insert newAccount;
               
                // Send opportunity to IT instance
                PartnerNetworkRecordConnection newrecord = new PartnerNetworkRecordConnection();
                newrecord.ConnectionId = cid;
                newrecord.LocalRecordId = acId;
                newrecord.SendClosedTasks = true;
                newrecord.SendOpenTasks = true;
                newrecord.SendEmails = true;
                //newrecord.ParentRecordId = acc.AccountId;
                System.debug('Inserting New Record'+newrecord);
                insert newrecord;
            }
        }
Thanks
G.
    }
}


Ashish_SFDCAshish_SFDC
Hi , 


Best Practice: Automatically share new accounts

Challenge: When new accounts or contacts are created in my org, I would like to share them automatically with another org.

Solution: You can push records from one org to another org using the PartnerNetworkRecordConnection object.

Here is the sample code you can use as a trigger on the Contact object.

http://wiki.developerforce.com/page/Best_Practices_for_Salesforce_to_Salesforce

http://wiki.developerforce.com/page/Best_Practices_for_Salesforce_to_Salesforce#Best_Practice:_Propagating_Account_and_Contact_merges

http://stackoverflow.com/questions/11643824/auto-accept-of-both-account-and-related-contacts-using-salesforce-to-salesforce

An App Exchange package : 

https://appexchange.salesforce.com/listingDetail?listingId=a0N30000003ILhKEAW&tab=r

Also see the below threads, 

https://developer.salesforce.com/forums?id=906F000000093V3IAI

http://salesforce.stackexchange.com/questions/3680/how-to-connect-salesforce-to-salesforce-in-apex


Regards,
Ashish