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
ABC XYZ 39ABC XYZ 39 

Compile Error: Expecting right parentheses, found '(' at line 48. Please assist. Thanks.

01if(Trigger.isInsert && Trigger.isAfter)
02{
03    ContactController.processContact(Trigger.newMap, Trigger.oldMap);
04}
05else if(Trigger.isUpdate && Trigger.isAfter)
06{
07    ContactController.processContact(Trigger.newMap, Trigger.oldMap);
08}
09 
10 
11 
12// call process contact on both insert and update
13public  void processContact(Map<Id, Contact> newContactMap, Map<Id, Contact> oldContactMap) 
14{ 
15    List<Queue__c> lstQ = new List<Queue__c>();    
16    Id idContactCustomerRecType;
17    Map<Id, String> mapIdToAccountName = new Map<Id, String>();
18     
19    // Assuming Developer Name is 'Customer'
20    List<RecordType> lstRecType = new List<RecordType>([SELECT Id FROMRecordType WHERE DeveloperName = 'Customer' AND SobjectType ='Contact']);
21    if(!lstRecType.isEmpty())
22        idContactCustomerRecType = lstRecType[0].Id;
23         
24    if(idContactCustomerRecType != null)
25    {
26        // we can;t fetch parent fields directly, so collect account Ids first
27        for(Contact objContact : newContactMap.values())
28        {
29            if(objContact.AccountId != null)
30                mapIdToAccountName.put(objContact.AccountId, null);
31        }
32    }
33     
34    // iterate over account with matching collected Ids and fetch names
35    for(Account objAccount : [SELECT Id, Name FROM Account WHERE Id IN : mapIdToAccountName.keySet()])
36    {
37        mapIdToAccountName.put(objAccount.Id, objAccount.Name);
38    }
39     
40    // loop again to perform business logic
41    for(Contact objContact : newContactMap.values())
42    {
43        /* 1. If Contact RecordType is Customer AND if LastName != Account.Name, insert Queue **/
44        if( objContact.RecordTypeId == idContactCustomerRecType 
45            && objContact.AccountId != null
46            && objContact.LastName != mapIdToAccountName.get(objContact.AccountId)
47            (
48                Trigger.isInsert
49                    ||
50                (
51                    Trigger.isUpdate
52                        &&
53                    (   
54                        objContact.A__c!= oldContactMap.get(objContact.Id).A__c
55                        || objContact.B__c!= oldContactMap.get(objContact.Id).B__c
56                        || objContact.D__c!= oldContactMap.get(objContact.Id).D__c
57                    )
58                )
59            )
60            )
61        {
62            Queue__c objQ = new Queue__c();
63            objQ.Object_Name__c='Contact';
64             
65            if(Trigger.isUpdate)
66            {
67                if(objContact.PID__c == null)
68                    objQ.Description__c= 'PID Missing';
69                else
70                    objQ.Description__c= 'Updated Contact';
71            }
72            else
73            {
74                objQ.Description__c= 'New Contact';
75            }
76             
77            objQ.Record_Id__c = objContact.Id;
78            objQ.Notification_Timestamp__c= objContact.CreatedDate;
79            lstQ.add(objQ);
80        }
81             
82    }
83     
84    if(!lstQ.isEmpty())
85        insert lstQ;
86     
87}
Best Answer chosen by ABC XYZ 39
Rohit Sharma 66Rohit Sharma 66
Try putting following Code inside your class:

    public  void processContact(Map<Id, Contact> newContactMap, Map<Id, Contact> oldContactMap)
    {
        List<Queue__c> lstQ = new List<Queue__c>();    
        Id idContactCustomerRecType;
        Map<Id, String> mapIdToAccountName = new Map<Id, String>();
        
        // Assuming Developer Name is 'Customer'
        List<RecordType> lstRecType = new List<RecordType>([SELECT Id FROM RecordType WHERE DeveloperName = 'Customer' AND SobjectType ='Contact']);
        if(!lstRecType.isEmpty())
            idContactCustomerRecType = lstRecType[0].Id;
             
        if(idContactCustomerRecType != null)
        {
            // we can;t fetch parent fields directly, so collect account Ids first
            for(Contact objContact : newContactMap.values())
            {
                if(objContact.AccountId != null)
                    mapIdToAccountName.put(objContact.AccountId, null);
            }
        }
         
        // iterate over account with matching collected Ids and fetch names
        for(Account objAccount : [SELECT Id, Name FROM Account WHERE Id IN : mapIdToAccountName.keySet()])
        {
            mapIdToAccountName.put(objAccount.Id, objAccount.Name);
        }
         
        // loop again to perform business logic
            for(Contact objContact : newContactMap.values())
            {
                /* 1. If Contact RecordType is Customer AND if LastName != Account.Name, insert Queue **/
                if( objContact.RecordTypeId == idContactCustomerRecType
                    && objContact.AccountId != null
                    && objContact.LastName != mapIdToAccountName.get(objContact.AccountId)){
                    
                      If(Trigger.isInsert || Trigger.isUpdate && (   
                            objContact.A__c!= oldContactMap.get(objContact.Id).A__c
                            || objContact.B__c!= oldContactMap.get(objContact.Id).B__c
                            || objContact.D__c!= oldContactMap.get(objContact.Id).D__c
                            )
                        ) {
                    Queue__c objQ = new Queue__c();
                    objQ.Object_Name__c='Contact';
                     
                    if(Trigger.isUpdate)
                    {
                        if(objContact.PID__c == null)
                            objQ.Description__c= 'PID Missing';
                        else
                            objQ.Description__c= 'Updated Contact';
                    }
                    else
                    {
                        objQ.Description__c= 'New Contact';
                    }
                     
                    objQ.Record_Id__c = objContact.Id;
                    objQ.Notification_Timestamp__c= objContact.CreatedDate;
                    lstQ.add(objQ);
                }
                     
            }
             
            if(!lstQ.isEmpty())
                insert lstQ;
        }
    }   

Let me know if it works

 

All Answers

ABC XYZ 39ABC XYZ 39
I am trying to fix this code for sometime. Please help. Thanks. 
Rohit Sharma 66Rohit Sharma 66
At line 47 use should use '{' in place of '('
Because Statements from line 48 are executing inside if condition, so it should be inside curly brackets { } and not inside the ().

Please let me know if this helps u.
Rohit Sharma 66Rohit Sharma 66
Try putting following Code inside your class:

    public  void processContact(Map<Id, Contact> newContactMap, Map<Id, Contact> oldContactMap)
    {
        List<Queue__c> lstQ = new List<Queue__c>();    
        Id idContactCustomerRecType;
        Map<Id, String> mapIdToAccountName = new Map<Id, String>();
        
        // Assuming Developer Name is 'Customer'
        List<RecordType> lstRecType = new List<RecordType>([SELECT Id FROM RecordType WHERE DeveloperName = 'Customer' AND SobjectType ='Contact']);
        if(!lstRecType.isEmpty())
            idContactCustomerRecType = lstRecType[0].Id;
             
        if(idContactCustomerRecType != null)
        {
            // we can;t fetch parent fields directly, so collect account Ids first
            for(Contact objContact : newContactMap.values())
            {
                if(objContact.AccountId != null)
                    mapIdToAccountName.put(objContact.AccountId, null);
            }
        }
         
        // iterate over account with matching collected Ids and fetch names
        for(Account objAccount : [SELECT Id, Name FROM Account WHERE Id IN : mapIdToAccountName.keySet()])
        {
            mapIdToAccountName.put(objAccount.Id, objAccount.Name);
        }
         
        // loop again to perform business logic
            for(Contact objContact : newContactMap.values())
            {
                /* 1. If Contact RecordType is Customer AND if LastName != Account.Name, insert Queue **/
                if( objContact.RecordTypeId == idContactCustomerRecType
                    && objContact.AccountId != null
                    && objContact.LastName != mapIdToAccountName.get(objContact.AccountId)){
                    
                      If(Trigger.isInsert || Trigger.isUpdate && (   
                            objContact.A__c!= oldContactMap.get(objContact.Id).A__c
                            || objContact.B__c!= oldContactMap.get(objContact.Id).B__c
                            || objContact.D__c!= oldContactMap.get(objContact.Id).D__c
                            )
                        ) {
                    Queue__c objQ = new Queue__c();
                    objQ.Object_Name__c='Contact';
                     
                    if(Trigger.isUpdate)
                    {
                        if(objContact.PID__c == null)
                            objQ.Description__c= 'PID Missing';
                        else
                            objQ.Description__c= 'Updated Contact';
                    }
                    else
                    {
                        objQ.Description__c= 'New Contact';
                    }
                     
                    objQ.Record_Id__c = objContact.Id;
                    objQ.Notification_Timestamp__c= objContact.CreatedDate;
                    lstQ.add(objQ);
                }
                     
            }
             
            if(!lstQ.isEmpty())
                insert lstQ;
        }
    }   

Let me know if it works

 
This was selected as the best answer
ABC XYZ 39ABC XYZ 39
thanks Rohit