1

I'm reposting this here, since I don't know if there's good place to share the tools and code.

I've published the first version of my component library today and I'd like to give it some recognition. I hope you will not mind.

Currently there're only a few components, but I hope you will find them interesting, and hopefully, useful in your work :) There are many interesting apex tricks involved, so perhaps this will give you idea for something awesome.

Everything is published under MIT license, so use this to your heart's content.

Link to repository.

Components:

  1. Collection class with methods that work on Lists, similar to JavaScript Array methods. Methods can be chained or used as static methods. Features:
    • Gathering field values to set
    • Mapping by field
    • Grouping by field
    • Filtering
    • Sorting by comparator
    • Wrapping records
    • reducing collection to single value
    • filling collection with SObject by prototype
    • other utility methods

From my experience, these operations occur in almost every business logic in Salesforce. After I've started to use Collections class, all that was left in my classes was pure business logic, with next to none list operations.

Map<Boolean, List<OpportunityWrapper>> actual = (Map<Boolean, List<OpportunityWrapper>>)
    new Collection(opportunities)
        .filter(Opportunity.CreatedDate, '>=', Date.today().addDays(-3))
        .filter(new CollectionFilters.ByFieldValues(Opportunity.StageName,'IN', new Set<Object>{'Analysis','Presales'}))
        .sort(Opportunity.Name, Collection.ASCENDING)
        .forEach(new AppendIndexToOpportunityNameWorker())
        .wrap(OpportunityWrapper.class)
        .groupBy(new WrapperByOpenActivityMapper());

This example is over complicated on purpose, I just wanted to show possibilities in one go.

  1. Datatable (click for full example)

    • Very robust, declarated through markup datatable. Similar to visualforce apex:datatable. In my opinion, it's the way that lightning:datatable should look like. You can bind inputs to the iterated values and actions to container component.

      <c:Datatable items="{!v.accounts}" var="account" paginate="true" bordered="true" responsive="true"
                   indexVar="index">
          <aura:set attribute="header">
              <c:DatatableRow>
                  <c:DatatableHeader value="Name" sortable="true" sortField="Name"/>
                  <c:DatatableHeader value="Record Type" sortable="true" comparator="{!v.comparators.RecordType}"/>
                  <c:DatatableHeader value="Phone" sortable="true" sortField="Phone"/>
                  <c:DatatableHeader value="Annual Revenue" sortable="true" sortField="AnnualRevenue"/>
              </c:DatatableRow>
          </aura:set>
      
          <aura:set attribute="body">
              <c:DatatableRow>
                  <aura:if isTrue="{!account.RecordType.Name != 'Competitor'}">
                      <c:DatatableColumn label="Phone" value="{!account.Phone}"/>
      
                      <aura:set attribute="else">
                          <c:DatatableColumn label="Contact Information" colspan="2"
                                             class="slds-text-align_center slds-theme--alert-texture">
                              Classified
                          </c:DatatableColumn>
                      </aura:set>
                  </aura:if>
      
      
                  <!--Finance-->
                  <c:DatatableColumn label="Annual Revenue">
                      <lightning:input type="number" value="{!account.AnnualRevenue}" variant="label-hidden"
                                       onchange="{!c.handleInputChange}"/>
                  </c:DatatableColumn>
      
      
                  <!--Buttons-->
                  <c:DatatableColumn label="Buttons">
                      <lightning:buttonIcon name="{!account.Id}" alternativeText="Delete" iconName="utility:close"
                                            size="large" onclick="{!c.handleDeleteAccount}"
                                            variant="bare"/>
                  </c:DatatableColumn>
              </c:DatatableRow>
          </aura:set>
      
      
          <aura:set attribute="footer">
              ...
          </aura:set>
      </c:Datatable>
      
  2. HttpCalloutChainMockRouter - example on how nestable callout mock can be implemented based on Chain of responsibility design pattern.

By using this pattern, you can have fully customizable mock router, which will be able to handle multiple different callouts and multiple integrations at the same time, while each unit test will be able to override the mocks to meet it's needs. Implementation is very simple, yet very powerful.

  1. XML Serializer / Deserializer Simple, yet smart tool which can automatically produce XML string from the nested instances of classes extending XMLNode. It can also reverse XML string to the instance of classes, with all fields populated from XML nodes and attributes.

Kind Regards,

  • 1
    I dont this this a question and what you are doing here is what SFMSE is designed for. I see you have posted same thing as an answer here salesforce.meta.stackexchange.com/questions/2266/… . Duplicating your github readme here doesnt really help. I am marking this for closure. – Pranay Jaiswal Sep 30 '18 at 1:43
  • @PranayJaiswal If that will benefit community in your opinion, then please do so. Description is a mess, I know it, it's hard to fit meaningful content in one block of text and hence I'm creating site for components library. This post will become obsolete then. – pkozuchowski Oct 1 '18 at 8:41
  • 1
    personally given the appaling nature of developer focused packages, i'd love a way for us to promote a particular managed package, provided it was specifically geared towards imrprovment the developer experience, no idea how that fits in the broader vision, @adrian_larson, perhaps something to consider in your disussion of what's meta and what's not? – Ralph Callaway Nov 7 '18 at 6:49
  • although could see this working better if the OP had to frame a question and then answer with their managed packages, so the community could add their own helper scripts – Ralph Callaway Nov 7 '18 at 6:50
  • 1
    the colloections method are pretty nice and would save a lot of boiler plate in my progrects, nice work – Ralph Callaway Nov 7 '18 at 6:50
  • @RalphCallaway Thank you :) I've started hosting my own library page, so I won't be spamming stack anymore salesforce-opensource-library.com – pkozuchowski Nov 8 '18 at 7:43

You must log in to answer this question.

Browse other questions tagged .