You need to sign in to do that
Don't have an account?
Sai Harshitha Bandlamudi
List has more than 1 row for assignment to SObject while autoforwarding objects using S2S
Hello All,
I am trying to implement S2S (Salesforce to salesforce) And I have written a code on Custom object called "ABC" to allow auto forwarding of records. After making the trigger active, I cannot manually create any records. Please help.
trigger SendABCToConnection on ABC__c(after insert,after update) {
PartnerNetworkConnection conn = [select Id, ConnectionStatus, ConnectionName from PartnerNetworkConnection where ConnectionStatus = 'Accepted' and ConnectionName = 'XYZ'];
List<PartnerNetworkRecordConnection> recordConnectionToInsert = new List<PartnerNetworkRecordConnection> ();
for (ABC__c acc : Trigger.new){
PartnerNetworkRecordConnection newrecord = new PartnerNetworkRecordConnection();
newrecord.ConnectionId = conn.Id;
newrecord.LocalRecordId = acc.id;
newrecord.SendClosedTasks = false;
newrecord.SendOpenTasks = false;
newrecord.SendEmails = false;
recordConnectionToInsert.add(newrecord);
}
if (recordConnectionToInsert.size() > 0){
System.debug('>>> Sharing ' + recordConnectionToInsert.size() + ' records');
insert recordConnectionToInsert;
}
}
The error I am getting:
Apex trigger SendABCToConnection caused an unexpected exception, contact your administrator: SendABCToConnection: execution of AfterInsert caused by: System.QueryException: List has more than 1 row for assignment to SObject: Trigger.SendABCToConnection: line 2, column 1
I am trying to implement S2S (Salesforce to salesforce) And I have written a code on Custom object called "ABC" to allow auto forwarding of records. After making the trigger active, I cannot manually create any records. Please help.
trigger SendABCToConnection on ABC__c(after insert,after update) {
PartnerNetworkConnection conn = [select Id, ConnectionStatus, ConnectionName from PartnerNetworkConnection where ConnectionStatus = 'Accepted' and ConnectionName = 'XYZ'];
List<PartnerNetworkRecordConnection> recordConnectionToInsert = new List<PartnerNetworkRecordConnection> ();
for (ABC__c acc : Trigger.new){
PartnerNetworkRecordConnection newrecord = new PartnerNetworkRecordConnection();
newrecord.ConnectionId = conn.Id;
newrecord.LocalRecordId = acc.id;
newrecord.SendClosedTasks = false;
newrecord.SendOpenTasks = false;
newrecord.SendEmails = false;
recordConnectionToInsert.add(newrecord);
}
if (recordConnectionToInsert.size() > 0){
System.debug('>>> Sharing ' + recordConnectionToInsert.size() + ' records');
insert recordConnectionToInsert;
}
}
The error I am getting:
Apex trigger SendABCToConnection caused an unexpected exception, contact your administrator: SendABCToConnection: execution of AfterInsert caused by: System.QueryException: List has more than 1 row for assignment to SObject: Trigger.SendABCToConnection: line 2, column 1
matt.ian.thomas
Setting the result of a query to a variable that isn't a list will throw a QueryException if the result set is anything but exactly 1 record. In this case, there are more than 1 "PartnerNetworkConnection" records returned in your query in the first line of your trigger, so you either need to change your variable declaration to be List<PartnerNetworkConnection> or modify your query such that it is ALWAYS returning 1 record. Alternatively, put it in a try-catch so that if and when it does return more than 1 result, you can do something about it rather than have it blow up entirely.
Deepak Gulian