What is Interface in Salesforce?

Conclusion

By providing a clear separation between a method declaration and implementation, interfaces enable the addition of an abstraction layer to code. As a result, it becomes possible to have different implementations of a method based on specific conditions.

Table of Contents

Recap to previous
Session

In the previous session, we learned how inheritance works in Salesforce.

Introduction to
Interface

By providing a clear separation between a method declaration and implementation, interfaces enable the addition of an abstraction layer to code. As a result, it becomes possible to have different implementations of a method based on specific conditions.

  • Within a class that is the interface, we can only define methods.
  • The interface cannot provide the implementations for its method.
  • The visibility of the methods will be controlled by the class that is implementing the interface.
  • In the interface, we cannot define any properties or variables except the methods.
  • Multiple interfaces can be implemented by a Single class.
  • A single interface can be implemented by Multiple Classes.
  • An Interface can extend another interface.
  • An interface can not be instantiated means an object can not be created

Interface Declaration


					
				

Examples

As an example, we can take from the Banks where every bank has its own interest for a different type of loans. Here is how the Apex Class will look like that is implementing the interface

Hands-On –

  • Implement discounts using the IPurchaseOrder Interface.
  • Implement Payment processing with IPaymentProcessor

Interface


					
				

The class that implements the interface. To implement the interface, we need to use implements keywords


					
				

					
				

					
				

Hands-On Code


					
				

					
				

					
				

					
				

					
				

					
				

					
				

					
				

					
				

					
				

					
				

Watch Complete Video

Resources

Amit Singh
Amit Singh

Amit Singh aka @sfdcpanther/pantherschools, a Salesforce Technical Architect, Consultant with over 8+ years of experience in Salesforce technology. 21x Certified. Blogger, Speaker, and Instructor. DevSecOps Champion

Articles: 299

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Leave a Reply

Your email address will not be published. Required fields are marked *

Discover more from Panther Schools

Subscribe now to keep reading and get access to the full archive.

Continue reading