You need to sign in to do that
Don't have an account?
golu
interface call in static methods
How do i call my interface from apex static methods.
I have a interface with below code:
Hi want to call a() and b() in another apex class .
How to do it? It throws error saying non-static methods cannot be referred from static context.
I have a interface with below code:
global interface xyz{ String a(); String b(); }
Hi want to call a() and b() in another apex class .
public static void createUpdateActivity(List<Communicato_History__c> lstComHistory){ List<id> activityids = new List<Id>(); if(activityids.size() > 0 && activityids.size() == 1 ){ // xyz.a(); }
How to do it? It throws error saying non-static methods cannot be referred from static context.
You can not call interface method without implementing the interface.
You Cannot call interface method without implementing.
Can you check reference link :
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_interfaces.htm
I hope it will help you.
Thanks & regards
Madhukar_Heptarc
You have to just implement your interface by implements keyword.Now if you use interface in your class, it will show error if you not override all the
implemented method.Try the below code.
public class Demo implements xyz{
public static void createUpdateActivity(List<Communicato_History__c> lstComHistory){
List<id> activityids = new List<Id>();
if(activityids.size() > 0 && activityids.size() == 1 ){
// xyz.a();
}
}
public String a() {
System.debug('In A');
}
public String b() {
System.debug('In B');
}
}
You can not call override method or any non-static method in static method.
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks,
Ajay Dubedi