Lead - gets converted to an Account , Contact and an Opportunity
I developed a trigger which shares an Opportunity and related Account with another Org of ours, and the piece 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 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;
}
}
}
}