You need to sign in to do that
Don't have an account?
ABC XYZ 39
Compile Error: Method does not exist or incorrect signature: [Map<Id,String>].get(Id, String) : How to Resolve?
Hi, I am getting compile error: Method does not exist or incorrenct signature for for mapIdToAccountName.get(objAccount.Id, objAccount.Name) at line 25. Not able to resolve this error. Please help. I am new to Apex programming. Thanks...
01public static void processNewContact(Map<Id, Contact> newContactMap, Map<Id, Contact> oldContactMap)
02{
03 List<Queue__c> lstQ = new List<Queue__c>();
04 Id idContactCustomerRecType;
05 Map<Id, String> mapIdToAccountName = new Map<Id, String>();
06
07 // Assuming Developer Name is 'Customer'
08 List<RecordType> lstRecType = new List<RecordType>([SELECT Id FROM RecordType WHEREDeveloperName = 'Customer' AND SobjectType = 'Contact']);
09 if(!lstRecType.isEmpty())
10 idContactCustomerRecType = lstRecType[0].Id;
11
12 if(idContactCustomerRecType != null)
13 {
14 // we can;t fetch parent fields directly, so collect account Ids first
15 for(Contact objContact : newContactMap.values())
16 {
17 if(objContact.AccountId != null)
18 mapIdToAccountName.put(objContact.AccountId, null);
19 }
20 }
21
22 // iterate over account with matching collected Ids and fetch names
23 for(Account objAccount : [SELECT Id, Name FROM Account WHERE Id IN : mapIdToAccountName.keySet()])
24 {
25 mapIdToAccountName.get(objAccount.Id, objAccount.Name);
26 }
27
28 // loop again to perform business logic
29 for(Contact objContact : newContactMap.values())
30 {
31 /* 1. If Contact RecordType is Customer AND if LastName != Account.Name, insert Queue **/
32 if(objContact.RecordTypeId == idContactCustomerRecType && objContact.AccountId != null && objContact.LastName != mapIdToAccountName.get(objContact.AccountId))
33 {
34 Queue__c objQ = new Queue__c();
35 objQ.Object_Name__c='Contact';
36 objQ.Description__c= 'New Contact';
37 objQ.Record_Id__c = objContact.Id;
38 objQ.Notification_Timestamp__c= objContact.CreatedDate;
39 lstQ.add(objQ);
40 }
41
42 }
43
44 if(!lstQ.isEmpty())
45 insert lstQ;
46
47}
01public static void processNewContact(Map<Id, Contact> newContactMap, Map<Id, Contact> oldContactMap)
02{
03 List<Queue__c> lstQ = new List<Queue__c>();
04 Id idContactCustomerRecType;
05 Map<Id, String> mapIdToAccountName = new Map<Id, String>();
06
07 // Assuming Developer Name is 'Customer'
08 List<RecordType> lstRecType = new List<RecordType>([SELECT Id FROM RecordType WHEREDeveloperName = 'Customer' AND SobjectType = 'Contact']);
09 if(!lstRecType.isEmpty())
10 idContactCustomerRecType = lstRecType[0].Id;
11
12 if(idContactCustomerRecType != null)
13 {
14 // we can;t fetch parent fields directly, so collect account Ids first
15 for(Contact objContact : newContactMap.values())
16 {
17 if(objContact.AccountId != null)
18 mapIdToAccountName.put(objContact.AccountId, null);
19 }
20 }
21
22 // iterate over account with matching collected Ids and fetch names
23 for(Account objAccount : [SELECT Id, Name FROM Account WHERE Id IN : mapIdToAccountName.keySet()])
24 {
25 mapIdToAccountName.get(objAccount.Id, objAccount.Name);
26 }
27
28 // loop again to perform business logic
29 for(Contact objContact : newContactMap.values())
30 {
31 /* 1. If Contact RecordType is Customer AND if LastName != Account.Name, insert Queue **/
32 if(objContact.RecordTypeId == idContactCustomerRecType && objContact.AccountId != null && objContact.LastName != mapIdToAccountName.get(objContact.AccountId))
33 {
34 Queue__c objQ = new Queue__c();
35 objQ.Object_Name__c='Contact';
36 objQ.Description__c= 'New Contact';
37 objQ.Record_Id__c = objContact.Id;
38 objQ.Notification_Timestamp__c= objContact.CreatedDate;
39 lstQ.add(objQ);
40 }
41
42 }
43
44 if(!lstQ.isEmpty())
45 insert lstQ;
46
47}
All Answers
As Nayana said you are writing the wrong syntax. You need to use "put" method to insert the data in map. And to retrieve the data from map we use get method.
mapIdToAccountName.
get(objAccount.Id, objAccount.Name);Use this method :
mapIdToAccountName.put(objAccount.Id, objAccount.Name);
Thanks.