We would like to set up a S2S connection to publish Cases to another org. But we only want cases with the custom field, Client Type = 'TypeA' to be sent. How can we prevent a user forwarding cases with a different Client Type? Thanks.
1 Answer
I can not give you a direct solution, but there is an indirect way if you are willing to automate s2s sending.
2 steps are required:
remove the button from the page layout (Case list view) - this will prevent users from manually sending Cases to another org.
create a trigger to automate sending. Example below.
trigger CaseShareWithConsultingOrg on Case (after insert, after update) {
List<PartnerNetworkConnection> connection = [select Id, ConnectionStatus, ConnectionName from PartnerNetworkConnection
where ConnectionStatus = 'Accepted'];
if(connection.size() > 0){
List<PartnerNetworkRecordConnection> recordToShareToInsert = new List<PartnerNetworkRecordConnection>();
for(Case myCase: Trigger.new){
PartnerNetworkRecordConnection recordToShare = new PartnerNetworkRecordConnection();
recordToShare.ConnectionId = connection[0].Id;
recordToShare.LocalRecordId = myCase.id;
recordToShare.SendClosedTasks = false;
recordToShare.SendOpenTasks = false;
recordToShare.SendEmails = false;
if(myCase.Clint_Type__c = 'TypeA') {
recordToShareToInsert.add(recordToShare);
}
}
try{
insert recordToShareToInsert;
}
catch (Exception e){
System.debug('CUSTOM ERROR === ' + e);
}
}
}
-
trailblazer.salesforce.com/ideaView?id=0874V000000lg6kQAA Commented Mar 13, 2021 at 12:34