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
idiris Abdukhamitov 1idiris Abdukhamitov 1 

How to use Trigger.NewMap in the class?

Who can help in this situation?

Class:  

public static List<ObjectName> MethosName(Map <Id, objectName> objectNameNewMap){logic}
trigger(beforeUpdate):

Trigger:

List<OnjectName> ObjectNameList = ClassName.methodName(Trigger.newMap);

ERROR:

Method does not exist or incorrect signature: void MethodeName(Map<Id,SObject>) from the type Classname

Best Answer chosen by idiris Abdukhamitov 1
idiris Abdukhamitov 1idiris Abdukhamitov 1
List<OnjectName> ObjectNameList = ClassName.methodName(Map<Id,ObjectName>Trigger.newMap); this helped me.

All Answers

Suraj Tripathi 47Suraj Tripathi 47
Hi Idiris,

You can take reference from this below code. Maybe this code will help you.
Class:  
public class ContactName {
    public static List<string> Method(Map <Id, Contact> objectNameNewMap){
        List<string> strList= new List<string>();
        for(Contact obj:objectNameNewMap.values()){
            strList.add(obj.Name);
        }
        return strList;
    }
}


trigger(beforeUpdate):
Trigger:
trigger triggerExample4 on Contact (before update) {
   
    if((trigger.isBefore && trigger.isUpdate)){
       List<string> conName=ContactName.method(trigger.newMap);
    }
}

In case you find any other issue please mention. 
If you find your Solution then mark this as the best answer. 

Thanks and Regards
Suraj Tripathi.
Maharajan CMaharajan C
Hi Idiris,

Please check the method name. In your sample am seeing the method name declared in class is different from it reffered in trigger.

Class:
public static List<ObjectName> MethosName(Map <Id, objectName> objectNameNewMap){logic}   // Here it is MethosName

Trigger:
List<OnjectName> ObjectNameList = ClassName.methodName(Trigger.newMap);  // Here it is methodName

If there is no same method name is not found in class also will throw this kind of error.

======================

Class:
public static List<ObjectName> methodName(Map <Id, objectName> objectNameNewMap){logic}   

Trigger:
List<OnjectName> ObjectNameList = ClassName.methodName(Trigger.newMap);

=====================

And Method parameter also needs to be same. for example If my trigger.newMap is coming from account trigger means it is Map<Id,Account> so in the class it should be public static List<ObjectName> methodName(Map<Id,Account>> NewMap). So verify you are passing the correct parameter or not.


Thanks,
Maharajan.C



 
idiris Abdukhamitov 1idiris Abdukhamitov 1
@Suraj Tripathi 47 : Didn't helped . Same error appears.
 
idiris Abdukhamitov 1idiris Abdukhamitov 1

Maharajan C:: Everything is correct. I did a mistake when was writing a question. But in sandbox everything is OK.
 
Suraj Tripathi 47Suraj Tripathi 47
Hi idiris,

Check this code:-
public class ContactName {
    public static List<string> Method(Map <Id, Contact> objectNameNewMap){
        List<string> strList= new List<string>();
        for(Contact obj:objectNameNewMap.values()){
            strList.add(obj.LastName);
        }
        return strList;
    }
}
 
trigger triggerExample4 on Contact (before update) {
   
    if((trigger.isBefore && trigger.isUpdate)){
       List<string> conName=ContactName.method(trigger.newMap);
    }
}
Please mark it as best answer if it helps.
Thanks.
 
idiris Abdukhamitov 1idiris Abdukhamitov 1
List<OnjectName> ObjectNameList = ClassName.methodName(Map<Id,ObjectName>Trigger.newMap); this helped me.
This was selected as the best answer