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
cherrysbluecherrysblue 

salesforce to salesforce automatically sharing a custom object or opportunity

I want to create a trigger for a customer object and opportunity we are sharing with another organization . I want to add a triger to the object and opportunity so whenever a new record insert, it can be automatically shared with another organizaion. 

 

Here is the code I wrote, I am not familiar with the code . so .........

 

trigger EDCSharing on Incentive__c (after insert) {

List<PartnerNetworkConnection)> connMap = new List<PartnerNetworkConnection>(
[select Id, ConnectionStatus, ConnectionName from PartnerNetworkConnection
where ConnectionStatus = 'Accepted']
);
for(PartnerNetworkConnection network : connMap) {
PartnerNetworkRecordConnection newrecord = new PartnerNetworkRecordConnection();

newrecord.ConnectionId = network.Id;
newrecord.LocalRecordId = accountId;
newrecord.RelatedRecords = 'Incentive__c';
newrecord.SendClosedTasks = true;
newrecord.SendOpenTasks = true;
newrecord.SendEmails = true;

insert newrecord;
}

 

 

And there is a error message said : there is unexpected token " list" 

~Onkar~Onkar

Hi cherry

 

look in red mark as you error due this barcket . remove baracket it will work.

 

 

trigger EDCSharing on Incentive__c (after insert) {

//List<PartnerNetworkConnection)> connMap = new List<PartnerNetworkConnection>(

List<PartnerNetworkConnection> connMap = new List<PartnerNetworkConnection>( // Correct Line
[select Id, ConnectionStatus, ConnectionName from PartnerNetworkConnection
where ConnectionStatus = 'Accepted']
);
for(PartnerNetworkConnection network : connMap) {
PartnerNetworkRecordConnection newrecord = new PartnerNetworkRecordConnection();

newrecord.ConnectionId = network.Id;
newrecord.LocalRecordId = accountId;
newrecord.RelatedRecords = 'Incentive__c';
newrecord.SendClosedTasks = true;
newrecord.SendOpenTasks = true;
newrecord.SendEmails = true;

insert newrecord;
}

cherrysbluecherrysblue

I tried that , I still have the same problem 

~Onkar~Onkar

May be you will get another typr of Error. Can you paste your complete code.

 

May be you will get the error related to AccountId.

 

~Thanks

Onkar Kumar

cherrysbluecherrysblue

this is my complete code. I am not familiar with the code .