Whenever Department is set to "US" opp automatically gets forwarded to other instance along with related account and contacts from that account, I got this error:
unexpected syntax: 'extraneous input ';' expecting RPAREN' at line 47 column 122
The specific line which throws the error is:
[Select Id, Name,(Select Id, Name From Contact)From Account Where Id in :oppIdvsAccountIdMap.getValues()]
What's wrong here, and how can I fix it?
Trigger AutoforwardOpp on Opportunity(after insert, before update)
{
List <PartnerNetworkRecordConnection> prncList;
List <PartnerNetworkConnection> connectionList;
Map <Id, PartnerNetworkConnection> connMap;
Map <Id, Id> oppIdvsAccountIdMap;
Map<Id, Account> accountWithContactMap;
if((Trigger.isAfter && Trigger.isInsert) || (Trigger.isBefore && Trigger.isUpdate) ){
String userName = UserInfo.getName();
String orgName = UserInfo.getOrganizationName();
String cid = network.Id;
String status = network.ConnectionStatus;
String connName = network.ConnectionName;
connectionList = new List<PartnerNetworkConnection>();
prncList = new List<PartnerNetworkRecordConnection>();
//This would ideally return multiple active Connections if they exist hence its best you use a
//criteria to ensure only the appropriate connection record is returned.
connMap = new Map<Id, PartnerNetworkConnection>(
[Select Id, ConnectionStatus, ConnectionName
From PartnerNetworkConnection
Where ConnectionStatus = 'Accepted']);
//get connection details
for(Id connId :connMap.keySet()){
cid = connMap.get(connId).Id;
status = connMap.get(connId).ConnectionStatus;
connName = connMap.get(connId).ConnectionName;
}
//Populate a map of Opp Ids and associated Account Ids
oppIdvsAccountIdMap = new Map<Id, Id>();
for(Opportunity oppRecord :Trigger.new){
if(opp.Department__c == 'US'){
oppIdvsAccountIdMap.add(oppRecord.Id, oppRecord.Account);
}
}
//Get associated Accounts and Contacts for every US opportunity if they exist
if(oppIdvsAccountIdMap.keySet().size() > 0){
accountWithContactMap = new Map<Id, Account>(
[Select Id, Name,(Select Id, Name From Contact)From Account Where Id in :oppIdvsAccountIdMap.getValues()];
);
//Create PartnerNetworkRecordConnections for sharing the records
for(Id oppId : oppIdvsAccountIdMap){
Id accountId = oppIdvsAccountIdMap.get(oppId);
//Share Opportunity
prncList.add(new PartnerNetworkRecordConnection(
ConnectionId = cid;
LocalRecordId = oppId;
SendClosedTasks = true;
SendOpenTasks = true;
SendEmails = true;));
//Share Account
if(oppIdvsAccountIdMap.get(oppId) != null){
prncList.add(new PartnerNetworkRecordConnection(
ConnectionId = cid;
LocalRecordId = accountId;
SendClosedTasks = true;
SendOpenTasks = true;
SendEmails = true;));
}
//Share associated Contacts
if(accountWithContactMap.get(accountId).Contacts != null){
for(Contact contact :accountWithContactMap.get(accountId).Contacts){
prncList.add(new PartnerNetworkRecordConnection(
ConnectionId = cid;
LocalRecordId = contact.Id;
SendClosedTasks = true;
SendOpenTasks = true;
SendEmails = true;));
}
}
}//for
//Insert record conneections
if(!prncList.isEmpty()){
try{
insert prncList;
}
catch(System.Dmlexception dmlExceptionInstance){
System.debug('Record Share Error:' + dmlExceptionInstance.getMessage());
}
}
}//if
}