Code Monkey home page Code Monkey logo

Comments (2)

afawcett avatar afawcett commented on August 14, 2024

I'm trying to understand your code here, so let me tell you how i've interpreted the above to arrive at my recommendation...

  • The 'bookapply' method does not look like a Domain class method. Since it is static and Domain class methods are instance level methods working on the Records property in conjunction with parameters passed in and i don't see this either.
  • Normally the Controller calls a Service class method, so is this what 'bookapply' method is?
  • So if the 'bookappy' method is really a Service class method, what is the purpose of it in a business sense? Is it to take a list of Email addresses and query for BookStore__c records?

If so, you should have three classes, controller > service class > selector class. In this case you don't strictly need a Domain class at this stage, though see my note below.

public class BookStoreController {
    public PageReference bookApply()
    {
         List<String> emails = null; // < Get list of Emails from view state?
         try {
              BookStoreService.bookApply(emails);
         } catch (Exception e) {
              ApexPages.addMessage(e):
        }
    }
}

public class BookStoreService {
    public static void bookApply(Set<String> emailAddresses) {
        List<BookStore__c> bookStores = 
             new BookStoresSelector().selectByEmail(emailAddresses);
        // Do something with the bookStores?
        // ...
     }
}

public class BookStoresSelector extends fflib_SObjectSelector {
    // See documentation for full example of methods to implement
    // ....

    public List<BookStore__c> selectByEmail(Set<String> emails) {
        assertIsAccessible();
        return Database.query(
            String.format('SELECT {0} FROM {1} WHERE Email__c in :emails ORDER BY {2}', 
            new List<String>{getFieldListString(),getSObjectName(),getOrderBy()}));
    }
}

You may wish to create a BookStores Domain class (especially if you have an Apex Trigger on this object). In which case you could encapsulate the behaviour of the bookApply logic in such a class and then call the BookStores Domain class from the Service method above. So the flow would be BookStoreController.bookApply > BookStoreService.bookApply > BookStoresSelector.selectByEmail > BookStores.bookApply

from fflib-apex-common.

afawcett avatar afawcett commented on August 14, 2024

Let me know if you want to continue to discuss, hopefully this moved things along for you! 👍

from fflib-apex-common.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.