1

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
    }
2
  • 1
    Your answer would be much improved if you indicate which line is 47 so we don't have to hunt through it ourselves. We also won't have to guess that you omitted any lines at the beginning of your file while copying to this post.
    – Adrian Larson
    Commented Aug 25, 2017 at 20:23
  • 1
    @AdrianLarson Sorry should have mentioned it, it's on query line [Select Id, Name,(Select Id, Name From Contact)From Account Where Id in :oppIdvsAccountIdMap.getValues()]
    – Admin_BA
    Commented Aug 25, 2017 at 20:28

3 Answers 3

2

The lines surrounding line 49 are these:

accountWithContactMap = new Map<Id, Account>( // Line 48
    [Select Id, Name,(Select Id, Name From Contact)From Account Where Id in :oppIdvsAccountIdMap.getValues()];
); // Line 50

To make things more clear, this is what you have:

accountWithContactMap = new Map<Id, Account>([<query here>];);

Whereas correct syntax is

accountWithContactMap = new Map<Id, Account>([<query here>]);

Your extra semicolon is the one sitting directly after your query, before the RPAREN ). Seems like this may have been a standalone query that you copu/pasta'd into a map constructor.

6
  • Thanks fixed those but found one more Illegal assignment from Schema.SObjectField to String at line 13 column 16 String cid = network.Id;
    – Admin_BA
    Commented Aug 25, 2017 at 20:38
  • Looks like you are trying to assign a String to a property of type Id. Try Id cid = network.Id;
    – JaredT
    Commented Aug 25, 2017 at 20:41
  • @Admin_BA gotta love how Salesforce reports errors on lines in ascending order. Yep, I too remember when I learned that 46 < 13. Joking aside though, as someone who knows the work involved in building a compiler, I can cut Salesforce a little slack here.
    – Derek F
    Commented Aug 25, 2017 at 20:41
  • @JaredT i get this error now Illegal assignment from Schema.SObjectField to Id at line 13 column 12
    – Admin_BA
    Commented Aug 25, 2017 at 20:44
  • @Admin_BA Additional errors should be added to your question (or have a separate question for them, but I feel all of these so far are fine to keep in one single question) rather than going back-and-forth in comments.
    – Derek F
    Commented Aug 25, 2017 at 20:46
3
prncList.add(new PartnerNetworkRecordConnection(
                ConnectionId = cid;
                LocalRecordId = oppId;
                SendClosedTasks = true;
                SendOpenTasks = true;
                SendEmails = true;));

In all your constructors you should delimit your fields with a comma, not semicolon:

prncList.add(new PartnerNetworkRecordConnection(
                ConnectionId = cid,
                LocalRecordId = oppId,
                SendClosedTasks = true,
                SendOpenTasks = true,
                SendEmails = true));
1
  • 1
    Good catch! This wasn't even on line 49 in the provided code (at time of writing). It isn't the only problem in the code though (but it would have been the next on OP would have run into).
    – Derek F
    Commented Aug 25, 2017 at 20:25
3

The other error is already addressed well, but the one on the indicated line is that you're missing the space between your SELECT and FROM clauses:

SELECT ... (...)FROM
               ^^
2
  • Still getting same error after giving space [Select Id, Name,(Select Id, Name From Contact) From Account Where Id in :oppIdvsAccountIdMap.getValues()];
    – Admin_BA
    Commented Aug 25, 2017 at 20:32
  • 2
    3 people, 3 different errors. Hooray for multiple eyes looking at a problem!
    – Derek F
    Commented Aug 25, 2017 at 20:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .