COMMUNICATE FROM A COMPONENT TO THE PAGE – VISUALFORCE

Visualforce has many different layers that make it easy to organize our pages and our code.  The visual portion of the page which includes the CSS, HTML and Apex Visualforce tags, which help to create more HTML, are kept in a Visuaforce Page.  This Visualforce Page then can point to an Apex Class, which should contain our business logic, by using the controller attribute.  The page would look like this:

1
2
3
4
5
6
7
8
9
10
11
12
<apex:page controller="blogController" showheader="true" sidebar="true">
   <apex:form>
      <apex:commandbutton value="Add 1" action="{!add1}" rerender="myIntPanel"></apex:commandbutton>
      <apex:commandbutton value="Subtract 1" action="{!subtract1}" rerender="myIntPanel"></apex:commandbutton>
      <apex:outputpanel id="myIntPanel">
        <apex:outputtext value="{!intVale}"></apex:outputtext>
      </apex:outputpanel>
   </apex:form>
</apex:page>

Here is our Apex Class that would contain the business logic related to that Visualforce Page:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
public with sharing class blogController{
   public integer intValue{get;set;}
   public blogController(){
      intValue = 0;
   }
   public pageReference add1(){
      intValue += 1;
      return null;  
   }
   public pageReference substract1(){
      intValue -=1;
      return null;
   }
}

This page and controller are pretty simple.  They allow you to manipulate the intValue integer on the controller.

But what if you had a component on that page and that component wanted you to add 5 or subtract 5 from the intValue?  How would it talk to the controller for the page?  It seems difficult because the page and the component will have different controllers.  But we can make this call by following a couple of steps to make the communication possible.  First, let’s add the add5() and subtract5() methods to our existing controller so it can be called.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
public with sharing class blogController{
   public integer intValue{get;set;}
   public blogController(){
      intValue = 0;
   }
   public pageReference add1(){
      intValue += 1;
      return null;  
   }
   public pageReference substract1(){
      intValue -=1;
      return null;
   }
   public pageReference add5(){
      intValue += 5;
      return null;  
   }
   public pageReference substract5(){
      intValue -=5;
      return null;
   }
}

Then on our page we could add these actionFunction items:

1
2
<apex:actionfunction action="{!add5}" name="add5" rerender="myIntPanel"></apex:actionfunction> 
<apex:actionfunction action="{!subtract5}" name="subtract5" rerender="myIntPanel"></apex:actionfunction> 

The actionFunction exposes a Javascript function that can be called from anywhere on the page, including from within components on that page.

This Javascript function then exposes a hook for our component to make a call back to the page itself.  Of course this is setting up a dependency between the component and the page on which it resides, but maybe that would be the correct situation in some use cases.

Here could be our component.  Notice how the buttons are calling the actionFunction items on the Visualforce page.  Let’s assume for later that we save our component file as Add5Subtract5.component.

1
2
3
4
<apex:component controller="blogComponentCtl">
     <apex:commandbutton value="Add 5" onclick="add5();return false;">
     <apex:commandbutton value="Subtract 5" onclick="subtract5();return false;">
</apex:commandbutton></apex:commandbutton></apex:component>

We do not even need to write out any code in the blogComponentCtl class, which is the controller for the component, because that class is not really helping us with this requirement.

We finally need to add the component to our page with the ‘c:’ notation.

1
2
3
4
5
6
7
8
9
10
11
12
13
<apex:page controller="blogController" showheader="true" sidebar="true">
   <apex:form>
      <c:add5subtract5></c:add5subtract5>
      <apex:commandbutton value="Add 1" action="{!add1}" rerender="myIntPanel"></apex:commandbutton>
      <apex:commandbutton value="Subtract 1" action="{!subtract1}" rerender="myIntPanel"></apex:commandbutton>
      <apex:outputpanel id="myIntPanel">
        <apex:outputtext value="{!intVale}"></apex:outputtext>
      </apex:outputpanel>
   </apex:form>
</apex:page>

Now everything should flow through.  The buttons in the component will call the actionFunction on the page, which will then call the desired method on the page’s controller.

There seems like a lot of steps there, but they really fit together pretty nicely.

Happy Visualforcing!

 

Posted in Technology | Tagged , , , | Leave a comment

A GREAT TYPE-AHEAD COMPONENT FOR VISUALFORCE

What is a type-ahead component?  When you start typing in characters in a textbox you either get options within the text-box itself or you get a list of matching items below the textbox.  What was needed in this project was a list of items below the textbox since there could be multiple matching items.

I was able to build a type-ahead component using a bit of javascript and a simple apex:datatable below the textbox, but that just didn’t look as good as what was needed for the project.

So what we found was this: https://github.com/SalesforceFoundation/visualforce-typeahead

This turned out to be a great find.  With this free component you are able to install it directly from into your org kind of like an un-managed package.  The install link can also be found on the GitHub link above.  Once it is installed you have complete control over the code, but that also means you have the responsibility of making sure any unit tests function properly if you change anything.

A picture here is worth a thousand words:

TypeAhead

 

You place this component on your apex:page using the standard c: notation…

1
2
3
<h3>Account Name:</h3>
<c:typeahead object="Account" destinationforselectedid="accountId"></c:typeahead>
<apex:hidden id="accountId" value="{!accountId}"></apex:hidden>

The example above says to place the selected value into the object referenced by the ‘destinationForSelectedId’ attribute, which in this case is the ‘accountId’ apex:hidden textbox.

What is so great about this component is that now that it is integrated in my project I can change and/or extend the functionality.  Maybe I want to use some special code in the Where clause of the SOSL query used within the Typeahead.cls class used by the component.  I could add code directly to the class or I could add a new parameter to the apex:component which is named Typeahead.component or I could try to work within the ‘filterClause’ parameter that already exists.  There are just so many options in my control.

Special thanks to Evan Callahan for figuring out how to wrap the typeahead.js library for twitter into a Salesforce component that we can all enjoy and extend.

Posted in Technology | Tagged , , , | Leave a comment

SALESFORCE 2015 WINTER RELEASE – MY FOUR FAVORITE DEVELOPER GOODIES

SALESFORCE 2015 WINTER RELEASE – MY FOUR FAVORITE DEVELOPER GOODIES

As Salesforce Developers we must have been ‘nice’ in 2014 because the Santa in Salesforce delivered some nice presents in the Winter 2015 release to make our lives easier.  New functionality means there is more to learn and train on within the Force.com platform, but those new features will help with all the creative ideas people have for automating their business processes.

So what goodies do we have with Winter 2015?  Here are four that stuck out to me…

1)  Deployment Enhancements
Anything in this area is so helpful.

The first new feature is being able to deploy an Apex class that is being used in conjunction with a scheduled job, batch job or future method.  We used to have to remove the scheduled job or make sure the batch job or future method was not running before a deployment.  Now the Salesforce deployment engine can help to manage this.

The second new deployment feature is called Quick Deploy.  Basically you first do a validation-only deployment.  Then if you do not do any deployments in the mean-time you can click on the ‘Quick Deploy’ link next to your successfully validated change set.  This will be great on those late evenings when we need the change set to deploy quickly so that other setup work can be completed.  As long as we planned ahead and did our validation early we can save some time during the actual deployment.  This feature must be enabled by Salesforce in your Org as it is in Pilot phase.

2)  The new Queueable Interface
I have always loved being able to chain batch jobs together.  But now with the Queueable interface we can kick off a new Apex class to execute.  This is very similar to a future call, but with two important enhancements.

a) You get an ID that you can use to monitor the job.  With future methods those were off running in the background and you had no access to them.
b) You can use the Queueable interface to kick off another Queueable class from the one that is currently running.  With future methods we could not make a future call from that future method.  This problem will not exist when using the Queueable interface.  Yeah!

3) Higher Limits for Future Methods and Callouts
You still have to be careful so that you do not put these actions in a loop that would break the new limits of 50 future calls and 100 callouts in a transaction.  But having these numbers will allow you to do things like having a higher batch size or processing more records within a loop.  With these types of higher numbers it will be interesting if we run into the governor limit that atransaction can only last for 10 seconds.

4)  The USING SCOPE SOQL keywords
The new USING SCOPE keywords, when used in SOQL, allows you to run queries that returns the records you would expect when setting up listviews.  It would look like this…

Select ID, Name From Contact USING SCOPE Mine

In this case ‘Mine’ would say to return everything that the logged in user owns.  It is the same thing as setting up a listview and checking the radio button to only return ‘My’ items.

Other values that can be used in place of ‘Mine’ are Everything, Queue, Delegated, MyTerritory, MyTeamTerritory or Team.  This link explains what each of these enumeration values will do.

Another great set!  Thanks Salesforce!

Posted in Technology | Tagged , , , | Leave a comment

THE EASE OF A CUSTOMER COMMUNITY – SALESFORCE

I recently read an article shared by our Director of Content Dean FroslieWhy Facebook’s Latest Algorithm Change is Great News For Content Marketers.  It had a lot of great insights related to new steps by Facebook to limit the reach of self-promoting brands and what Forrester research thinks about brand investments in Facebook and Twitter.

But the paragraph in this article that struck me was a quote from Nate Elliott, who wrote the Forrester report…

his[Elliot’s] “favorite” prediction for 2015 is branded communities will make a comeback: “Invite a few hundred of your most satisfied customers into an exclusive forum, issue them word-of-mouth challenges, rank them on a leaderboard, and watch your reach multiply.”

This is exactly what Salesforce is going after with its Customer Community platform.  The basic configuration of a Custom Community for logging in, submitting ideas, conversing in groups, reviewing content and submitting cases is all point-n-click.  It is already a branded community with the simple addition of a logo and your specific colors.  But it can be extended as far as you want to go after that.  You can make it a custom branded community by creating a customized web site built with Visualforce. On the simpler side you can add some specific tabs in the community that will display web pages with specifically targeted content.

The flexibility is all in your hands!

Here are a couple of other blog posts I have written in relation to Communities on the Force.com platform.
1) The Transition in Salesforce from Portals to Communities
2) Salesforce Communities – Let’s Get Customizing!

Please reach out if we at Sundog can help answer any questions related to the communities that you would like to start to promote your brand.

Posted in Technology | Tagged , , , , | Leave a comment

THE MULTI-PLATFORM MANDATE

The potent combination of shifting mobile behaviors, social media adoption and device proliferation means our content must be available anywhere, at any time.

In the retail world, for example, content must be readily available (and well-optimized for search engines) during in-store experiences. According to Google’s Mobile In-Store Research study:

  • 84% of smartphone shoppers use their phones while in a physical store.
  • 90% of smartphone shoppers use their phone for pre-shopping activities.
  • 1 in 3 shoppers use their smartphones to find information instead of asking store employees.
  • 82% of shoppers use search engines when browsing product information in-store.

These expectations extend beyond the retail experience. In fact, consumers demand nearly any content, at any time. According to Mobile Marketer:

“the challenge companies must address but few are doing is that consumers increasingly expect to be able to engage with brands to get any information or service they desire immediately and in context.”

How well have organizations adapted to these behaviors and expectations? Much work is ahead. Consider a recent mobile behavior report from ExactTarget (2014):

  • 54% of survey respondents say mobile-optimized websites don’t give enough information.
  • More than nine out of ten consumers say that access to content however they want it is somewhat or very important; 59% say it’s very important.
  • Similarly, 83% say a seamless experience across all devices is somewhat or very important.

So do these stats really mean anything for a customer’s journey? Absolutely, as a McKinsey report notes:

How companies engage customers in these digital channels matters profoundly—not just because of the immediate opportunities to convert interest to sales but because two-thirds of the decisions customers make are informed by the quality of their experiences all along their journey, according to research by our colleagues.

It’s easy to think you’ve “solved” mobile by creating a scaled-back mobile site with scaled-back content. For many organizations, this has been an acceptable workaround but it isn’t a sustainable long-term solution. The ultimate goal should be clear: All of your content should be available on any device.

Posted in Technology | Tagged , , | Leave a comment

MARK YOUR CALENDAR: LIVE HEALTHCARE & B2B WEBINARS NEXT WEEK

Ready to step up your customer or patient journey?

Come join our free “The Extra Mile” webinars next week, specializing in healthcare and B2B + manufacturing. And walk away with cool tips, tools and takeaways – customized for your industry.

Here’s the inside scoop:

1. Healthcare Webinar: Tuesday, November 11
11:30 am – 12:20 pm CT

Join us to learn about a full-circle approach to healthcare, featuring …

  • Complete mobile integration (plus tablets and wearable tech)
  • Activity, vitals, nutrition and metabolic tracking
  • Targeted micro-motivational and micro-educational content
  • Communities for peer and provider support
  • Personalized experiences by patient segment
  • Automated dashboards and reports – all integrated into healthcare practice

 

But what does all that really mean for you?

  • Transform your patient outcomes. Not to mention your ROI.
  • Engage new and existing patients in managing their health, not just their sick care.
  • Reduce effort for your patients and increase efficiency for your staff.
  • And that’s just the beginning.

Register free online >
2. B2B & Manufacturing Webinar: Thursday, November 13
11:30 am – 12:20 pm CT

Want to see direct results through indirect sales channels? See how make it simple, using one holistic solution built with:

  • Industry-specific journeys
  • Segment-specific messaging
  • Marketing automation
  • Partner communities, marketing tracks and scorecards
  • Integrated campaign planning
  • Outcome-driven insights using the latest marketing tech, web analytics, tag management and CRM

The results?

  • Attract and qualify more customers and prospects.
  • Create a unified brand experience, end to end.
  • Increase your sales and improve lead management.
  • Get real-time insights and analytics – at every step.
  • And much more.

Register free online >

Want to Learn More? 
You can check out our speakers, along with more info about each webinar online.
Healthcare: See details & preview
B2B & Manufacturing: See details & preview

Hope you can make it!

 

Posted in Technology | Tagged , , , , | Leave a comment

WHAT’S YOUR CORE CONTENT STRATEGY?

Many organizations may think they have a clear direction for content, yet few actually formalize it.

Similar to an organizational mission statement, your core content strategy should establish your long-term direction. In Content Strategy for the Web, Kristina Halvorson and Melissa Rach state that the “core strategy sets the long-term direction for all of your content-related initiatives—ensuring all activities, big or small, are working together toward the same magnificent future.” It helps you establish:

  • What you attend to accomplish
  • Who you need to reach and what you’ll create
  • Outcomes you want to achieve
  • Direction for content decisions and contributors

Joe Pulizzi advocates developing a mission statement for content marketing that revolves around your audiences, not your organization:

Remember, content marketing is not about “what you sell,” it’s about “what you stand for.” The informational needs of your customers and prospects come first…To work, your mission statement has to be all about the pain points of your readers and followers or it simply won’t work.

Core strategy statements are even an effective approach for individual tactics or channels. In their presentation at Confab Central, Amy Lavoie, Aura Seltzer and Sara Wachter-Boettcher shared their strategy statement for the Harvard University website redesign project. Similar to Pulizzi’s guidance, it’s highly audience-centric:

Turn talented, diverse prospects into confident applicants—and successful Harvard students—with content that makes Harvard feel within reach, creates a sense of belonging, and clarifies the path from application to graduation.

Taken a step further, your mission statement or strategy statement can be supported by a series of principles that create greater alignment and common ground. In digital circles, the gov.uk website has attracted attention for its openness and transparency, which includes a series of design principles:
1. Start with needs
2. Do less
3. Design with data
4. Do the hard work to make it simple
5. Iterate. Then iterate again.
6. Build for inclusion
7. Understand context
8. Build digital services, not websites
9. Be consistent, not uniform
10. Make things open: it makes things better

Only 35% of marketers have documented their content marketing strategy at all. When you take that step, be sure it’s grounded by a thoughtful purpose statement.

Posted in Technology | Tagged , | Leave a comment

CALCULATING CALENDAR HOURS IN SALESFORCE

In this blog post regarding Business Hours, Calculating Business Hours in Salesforce, I described how you can use the built-in Business Hours point-n-click window along with the BusinessHours Apex class to determine Business Hours.  That was really slick.

But within the same project you may be asked to calculate ‘Calendar Hours’ too.  I would define ‘Calendar Hours’ as simply adding the number of defined hours to the current date and time.  So if it is 3pm and you want to add 25 calendar hours, then you should get 4pm tomorrow.

This can be done with a line in Apex like
myDateTime = myDateTime.addHours(25);

In the discussion of ‘Calendar Hours’ you also need to determine if you are going to include weekends and holidays into your calculations.  If you do not want to include those hours, then it is pretty cool that you can use the Business Hours objects in Salesforce to help with your calculations.

Simply setup a ‘Business Hours’ row under the Setup option that defines your weekdays as being open 24 hours a day Monday through Friday.  Then setup the hours on Saturday and Sunday as not being open at all.  Finally add any Holidays that you want to these configured Business Hours.

So then instead of using the ‘addHours’ method we can leverage the BusinessHours object:

list<BusinessHours> bhList = new list<BusinessHours>();
bhList = [Select ID From BusinessHours Where Name = ‘My Calendar Hours’];
newDateTime = BusinessHours.addGMT(bhList[0].ID, currentDateTime, 1000 * 60 * 60 * hoursToAdd);

That is it!  Wow!  I do not need to write Apex code to exclude weekends or holidays.  Yeah!

Posted in Technology | Tagged , , , | Leave a comment

WHY TAYLOR SWIFT IS THE QUEEN OF DIGITAL MEDIA

Her music makes a statement for itself, when her album has been getting only positive reviews from Time Magazine, Rolling Stones and New York Times. Her album is making a statement of a more confident and older Taylor Swift.

Time Magazine says, “1989 marks her most impressive slight of hand yet, shifting the focus away from her past and onto music which is as confident as she has ever been.” And “In the song, Shake It Off, the singer has written herself a narrative in which she’s still the outsider and a small-town girl learning to navigate the big city.”

Rolling Stones says, “1989 sounds exactly like Taylor Swift even when its something she has never done before.”

New York Times states, “By making pop with almost no contemporary references, Ms. Swift is aiming somewhere even hirer, a mode of timelessness, few pop starts even bother aspiring to.”

As the new album is surpassing expectations, Swift is also the queen of digital media. She is making herself known doing some of the most strategic and innovative social networking and digital marketing campaigns ever.

This past summer, Swift forced herself to learn Tumblr. Then, she took advantage of a post going viral and posted a response through a MEME that was funny yet charming. She used her Polaroid 1989 template to capture the image, which helped tie the MEME to her new album release. Read more here.

This was one of many things; Taylor launched leading up to her new album. Let’s take a walk back in time to review the timeline and how she leveraged digital media.

• Swift uses Instagram to share clues that have to be pieced together, which led up to her Yahoo Live Web Chat.
• On the Yahoo Live Web Chat, Swift announces new album and new music video of the first single “Shake It Off. To date, this video has over 198,300,828 million views on YouTube.
• After a couple weeks of “Shake It Off,” Swift releases slowly outtake videos of her talking behind the scenes of each segment in the music video. On average, each of these videos has over 1-3 million views each. There are about 8 of these videos.
• Swift also has been hosting multiple private album listening sessions where she has invited about 100 fans to meet her in person, listen to the album and take photos with each fan. She has been sharing a few on Instagram and leveraging her fans to share them as well.
• She also has lined up some of the most watched night talk shows to guest speak and perform including Jimmy Fallon and Jimmy Kimmel which also utilize YouTube to recap the show very well after the live air date.
• On Social Media, Swift is also releasing sneak peeks of lyrics from her new album through an Instagram campaign.
• Voice memos are another piece of the behind the scenes Swift is sharing as the new album releases.
• She leverages the hashtag #1989Swiftstakes for a contest for her fans to enter win a chance to meet the star.
• Also encouraging fans to host an album launch parties and receive a special message from Swift.
• As fans recreated her video “Shake it Off” video, Swift shared some of the user generated content on her network enhancing and building the relationship with her fans.

Ms. Swift keeps her audience engaged, leverages the community and gives back through sharing user generated content in addition to her own authentic voice. In this digital world, every brand could use a lesson from the one and only T. Swift.

Posted in Technology | Tagged , , | Leave a comment

CALCULATING BUSINESS HOURS IN SALESFORCE

Business hours may need to be calculated for a number of reasons.  Your functional area may have set up Service Level Agreements or SLAs that say you must complete a certain activity within a certain time period in order to make the business unit run effectively.  A related concept is Turn Around Time or TAT, where maybe a government agency has created a hard rule or law that must be followed for finishing a certain activity.

A requirement could be that a certain piece of paperwork must be processed within 4 business hours.  That statement seems pretty simple until you start taking into account how you can possibly do that calculation for business hours.  First, you should clarify that the calculation is not really just calendar hours.  A calculation for calendar hours is usually much simpler than for business hours in that you can usually just add hours using a simply date.addHours() function in Salesforce Apex.  Even with calendar hours you still need to take into account things like weekends and holidays, but you still do not have to deal with the business hours too.

A first question to ask during the requirements gathering is whether the business hours are the same across all business units.  The nice part is that if hours are the same or different that Salesforce can manage that requirement if we use the Business Hours functionality.  If you go to the Setup menu in Salesforce and then drill down through Administer, Company Profile you will get to Business Hours.  This is a point-n-click feature that is used with other features like escalation rules and entitlement processes.  But we can also use it for helping us to figure out our own SLA or TAT rules.

You can setup one set of Business Hours to be the default hours for the company.  Then other Business Hours can be setup to be used for specific business units.  How would you tie a set of Business Hours to a specific Account for example?  It is really simple actually.  You can just create a lookup field on the Account object to the Business Hours object.  Then each account could have its own set of Business Hours.

So now we have a set of Business Hours for each account, but how do I add 4 business hours to a date field that I might have on my Account record?

This can be done with a before trigger on the Account object and the solution leverages some built-in functions in Apex.

The first Apex feature to recognize is the BusinessHours class which has a method called BusinessHours.addGMT().  DateTime values are returned in Salesforce Apex in GTM so using the addGMT() method makes the most sense.  It is really easy to use.  You first just need to figure out which Business Hours you need to use.  So if you have your AccountID and you have setup a lookup field on the Account object to BusinessHours your query could be something like…

Account myAccount = [Select ID, DateToAddHours__c, BusinessHours__c From Account Where ID = :accountID];

You could then add your 4 hours to that date on the Account object with…

dateTime myNewDateTime = BusinessHours.addGMT(myAccount .BusinessHours__c, myAccount.DateToAddHours__c, 1000 * 60 * 60 * 4);

Notice in the formula below that the last parameter is the number of milliseconds so the 1000 * 60 * 60 gives you the number of milliseconds in an hour so then we can just add the number of hours to multiply onto the end.

So in the end if values for our computation are…
1) Our business hours are 8-5pm Monday through Friday
2) We chose 3pm to be our starting date
3) We want to add 4 hours to this starting date

The result will be 10am on Monday.  This is because we have two hours left on Friday and we need to add two more hours onto Monday.

This actually does take into account any weekend calculations so we do not have to deal with those either.  The only thing left to take into account are any holidays.  But what is great is that holidays can be added right to the Business Hours when they are setup in Salesforce.  There is a whole Holidays feature in Salesforce that can even set up recurring holidays.

That is great!  So basically with one line of code in an Apex Trigger we can determine some great calculations regarding Business Hours.

If we can help you setup any SLA or TAT type rules in your Salesforce org please let us know at Sundog!

Posted in Technology | Tagged , , , | Leave a comment