You need to sign in to do that
Don't have an account?
ABC XYZ 39
Can't get this simple piece of code of work : Contact.lastname should not be equal to Account Name in Apex Class? Please help
Basic Logic is : Every new contact of record type 'customer' will be inserted into q Queue object. Additional logic is the new contact won't be inserted into the Queue if Contact's last name is not qual to Account Name. This is what I am unable to implement. I have tried to use this condition everywhere in the logic. It simple does not work. I am new to Apex programming. Please help.
Logic :
public static void processNewContact(Map<Id, Contact> newContactMap, Map<Id, Contact> oldContactMap) {
List<Queue__c> objList = new List<Queue__c>();
Map<id, recordtype> contactRecTypeMap = new Map<id, recordType>([select id from Recordtype where SobjectType='Contact' and Name = 'Customer']);
if(contactRecTypeMap!=null ){
System.debug('RECORDTYPES RETRIEVED>>>' + contactRecTypeMap + 'size>>>' + contactRecTypeMap.size());
// if(contact.account.name!=contact.lastname) {
for(Contact c: newContactMap.values()) {
// if(c.account.name!=c.lastname) {
System.debug('checking for last name and account name entry >>>> If Loop1 >>' + c.lastname + c.account.name);
// if(c.account.name!=null && c.lastname!=c.account.name) {
// if(c.lastname!=c.account.name) {
if(contactRecTypeMap !=null && contactRecTypeMap.keySet().contains(c.recordtypeID)){
// if(c.lastname!=c.account.name) {
Queue__c q1 = new Queue__c();
q1.Object_Name__c='Contact';
q1.Description__c= 'New Contact';
q.Record_Id__c = C.Id;
q1.Notification_Timestamp__c= c.CreatedDate;
/* if(c.lastname!=c.account.name) {
objList.add(obj1);
}
else {
delete objList;
} */
}
// }
// }
}
}
}
Logic :
public static void processNewContact(Map<Id, Contact> newContactMap, Map<Id, Contact> oldContactMap) {
List<Queue__c> objList = new List<Queue__c>();
Map<id, recordtype> contactRecTypeMap = new Map<id, recordType>([select id from Recordtype where SobjectType='Contact' and Name = 'Customer']);
if(contactRecTypeMap!=null ){
System.debug('RECORDTYPES RETRIEVED>>>' + contactRecTypeMap + 'size>>>' + contactRecTypeMap.size());
// if(contact.account.name!=contact.lastname) {
for(Contact c: newContactMap.values()) {
// if(c.account.name!=c.lastname) {
System.debug('checking for last name and account name entry >>>> If Loop1 >>' + c.lastname + c.account.name);
// if(c.account.name!=null && c.lastname!=c.account.name) {
// if(c.lastname!=c.account.name) {
if(contactRecTypeMap !=null && contactRecTypeMap.keySet().contains(c.recordtypeID)){
// if(c.lastname!=c.account.name) {
Queue__c q1 = new Queue__c();
q1.Object_Name__c='Contact';
q1.Description__c= 'New Contact';
q.Record_Id__c = C.Id;
q1.Notification_Timestamp__c= c.CreatedDate;
/* if(c.lastname!=c.account.name) {
objList.add(obj1);
}
else {
delete objList;
} */
}
// }
// }
}
}
}
All Answers
Error: Compile Error: Method does not exist or incorrect signature: [Map<Id,String>].get(Id, String) for mapIdToAccountName.get(objAccount.Id, objAccount.Name);
how to resolve it?
Extremely sorry for this.
I have another similar scenario like the one I discussed. This is an update scenario
Logic :
If contact record type is 'Customer' --then check whether record has been modified by 'X' user --> If the record has been modified --> Check whether A,B,C field values have changes ---> If the field values have changed --> Then, insert into the Queue object
How can I best write a test class for this scenario? Please assist. Thanks.