使用Sales Force到Sales Force Connector将主要联系人与Opportunity共享

时间:2014-02-24 21:44:45

标签: salesforce

潜在客户 - 转换为账户,联系人和机会

我开发了一个触发器,它与我们的另一个Org共享一个机会和相关帐户,而我错过的部分是与此共享联系人。需要一些帮助来分享联系人。

     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 Opp = Trigger.new[i];
    String acId = Opp.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 = Opp.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 = Opp.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 = Opp.AccountId;
            System.debug('Inserting New Record'+newrecord);
            insert newrecord;
        }
    }
    }
}

1 个答案:

答案 0 :(得分:0)

newrecord.RelatedRecords =&#39;联系人,机会&#39; //等