Salesforce License Information with APEX

If you want to get certain Salesforce user license information from within your org via APEX, such as TotalLicenses, you will have to either screen scrape the information from your org or sign up for Salesforces user license pilot program.

Signing up for the pilot program is a much better idea.  If you try to screen scrape, then the page layout you’re scraping from might change and you will need to keep up with page changes.

When you signup for the pilot program, the Salesforce documentation says it is only available through the SOAP API and this poses it’s own set of issues.  If you use the SOAP API, you will need to use the login method or add your current login session Id into the SOAP header.  If you need to use it in a scheduled job, you won’t have access to the current session Id.  I have a quick solution so you won’t have to deal with the complexity of using the API and storing login/passwords/tokens.

You can use Database.query

List<sObject> sobjList = Database.query('SELECT MasterLabel, Status, TotalLicenses, UsedLicenses FROM UserLicense');

for (sObject o : sobjList) {
    String sMasterLabel = (String) o.get('MasterLabel');
    String sStatus = (String) o.get('Status');
    Integer nTotalLicenses = (Integer) o.get('TotalLicenses');
    Integer nUsedLicenses = (Integer) o.get('UsedLicenses');

Thats it! You can avoid using the API (only if you signed up for the UserLicense pilot program).

pcDuino3 Nano Lite

pcduino3nanoliteOnly a few short years ago, the world was introduced to the Raspberry Pi, the $35 computer.  Its hard to image that a device that small can do so much, but it does.  That single device has seemed to have created a whole new market of single board computers.  We now have the Raspberry Pi 2, Banana Pi, Orange Pi, Beagle Bone, pcDuino, etc.  Most of these devices are based on the ARM processor.  Each device has its own set of specs and features, and that makes certain ones useful for certain projects, and others are better suited for others.

I picked up the pcDuino3 Nano Lite from Amazon for $15!  For the price I couldn’t pass up the chance at grabbing one and testing it out.  What makes this board unique is it supports gigabit ethernet and a SATA port.  The ethernet and SATA port are integrated into the Allwinner A20 chip, so it’s not an extra USB add on, so performance should be great.


  • CPU: AllWinner A20 SoC, 1GHz ARM Cortex A7 Dual Core
  • GPU: OpenGL ES2.0, OpenVG 1.1, Mali 400 Dual Core
  • DRAM: 1GB
  • Onboard Storage: MicroSD card (TF) slot for up to 32GB
  • Arduino extension interface: Arduino sockets, same as Arduino UNO 14xGPIO, 2xPWM, 6xADC, 1xUART, 1xSPI, 1xI2C

I used a SanDisk Ultra 32 GB card from Amazon for only $10.  I really like using these cards because their fast and cheap.  I haven’t had any issues using this card in any of my devices whether its a camera or single board pc.

For the OS, I used Armbian.  There are 2 choices you can download, Legacy and Vanilla.  The difference between the 2 are what version of the kernel it uses.  I chose the Legacy jessie (Debian) because at the time, it had better hardware support.  The mainline kernel is progressing nicely, so by this time, vanilla might be a better choice.

Overall, I am very happy with the device.  It has been running rock solid for the last 5 months as a production server with no reboots.  The footprint is small, and power consumption is low, making it perfect for a mail server, nagios server or and other small uses.

MySQL Binary Logs and Replication

If you’re a MySQL admin and use replication in either a master-slave or master-master setup, you no doubt had replication fail at one point or another.  This situation can be quite scary and fixing it can range from being simple to being very complex where rebuilding a database server is the only option.

Hopefully I can lend a few tips and tricks to help you resolve your issue.

Binary Logs

MySQL binary logs can be thought of as files that contain a record of SQL statements, in chronological order, that would alter your data.  Some types of commands that are stored are CREATE, INSERT, DELETE, etc.  These commands are stored with the position at which they occurred.  So, lets say for instance you had database at position 10 (real world positions are much larger), a dump taken at position 5, had the binary logs that contained 5-10.  Then, with only the dump and binary log, you can rebuild your database to position 10.

Backup Your Data

First things first, I hope you regularly backup your data.  There are 2 easy ways to backup your data, full dump with master data (contains binary log information) and databases only.  The problem with database only is that the most you can restore to is that point in time that snapshot was taken at and you would need to rebuild all your DB servers.  At least with master data, you have the binary logs to rebuild to in case your file became corrupted and can rebuild just the server that went down.

Master Data:
mysqldump –all-databases –master-data -u user -ppass > mydata.sql

Databases Only:
mysqldump –all-databases –single-transaction -u user -ppass > mydata.sql

Show Slave Status

Open mysql command line interface and connect it to your running MySQL server box, then run:


There are 4 fields that are extremely useful to look at Slave_IO_Running, Slave_SQL_Running, Seconds_Behind_Master and Last_Error.

Slave_IO_Running – Should be yes unless STOP SLAVE was issued.

Slave_SQL_Running – Tells if the commands from thy logs are running.

Seconds_Behind_Master – This should normally be near 0, a high number (or NULL) indicates that the slave is far behind the master.  I should mention, this is not really the number of seconds behind the master, but more of the bigger the number, the farther behind master.

Last_Error – The last SQL statement that caused an error when running the relay log.  We want this to be blank.

Fixing The Error

I see a lot of posts out there that say just do SET GLOBAL SQL_SLAVE_SKIP_COUNTER = 1; START SLAVE; and while this will hopefully get you past the error, you really should know why the statement is failing.  If you just run that command, you will most likely lose data.

Ask yourself, if you skip the SQL statement, will it be bad for my data?  If it’s just a inserting logging data, it’s not such a big deal, but if it inserts an order into your ecommerce website, you will lose that order in the slave database.  The master and slave databases will then be inconsistent and will not mirror each other.  I first like to verify if that SQL statement executed on the master.  If it was an insert, see if it inserted, if it was a delete, see if it deleted.

After you verify the failing statement, and only after you know there aren’t any dire side effects, then you can run SET GLOBAL SQL_SLAVE_SKIP_COUNTER = 1; START SLAVE; .  This will skip the current error statement and try the next.  Remember, never skip more then 1 at a time, that this record may be a key to another insert (foreign key) and might cause a chain reaction, and never skip if you cant recover lost data.

Catastrophe Strikes!

You skipped a bunch of statements, perhaps your file is corrupted, or maybe the drive just died.  Any one of these things could happen, just know when to tap out.  As a last resort, I just go onto the master server and create a dump with –master-data as described above, then on the slave, make sure MySQL is not running, delete the data and binary log files, start MySQL and import the dump via command line.  After the import, run SHOW SLAVE STATUS to find out the master file and position, then run CHANGE MASTER TO to set all slave information and also using the values that were imported (and shown in slave status) set MASTER_LOG_FILE,  MASTER_LOG_POS appropriately (needs to be done in 1 command).  The CHANGE MASTER TO must contain all your slave info, then when done, START SLAVE.  This will catch up to the master in a short time.


There are many ways to deal with MySQL and as time goes on, you’ll pick up tricks.  Always have a local and remote backup and never panic.  And remember, call a DB admin if you can’t figure it out before it becomes unrepairable.

1999 Ford Windstar Headlights Stay On, Wont Start

OK, so this post will be a little different from normal, but hopefully someone will find it useful.

Our 1999 Ford Windstar hasn’t been acting right lately, so we replaced the battery.  After hooking up the new battery, the running lights came on and the van wouldn’t start (the starter wouldn’t even engage).  No matter what we did, we couldn’t get the lights to turn off.  The radio would also turn on without the key in the ignition, and with they key in, the door/key chime wouldn’t turn on.  We checked every fuse and relay with the multitester, all tested good.

It turned out the problem was the ignition switch was bad.

WARNING: This vehicle contains SRS, or airbags, DO NOT WORK ON THIS AS AIRBAGS CAN ACCIDENTALLY DEPLOY AND BE VERY DANGEROUS.  If you choose to ignore my warning and still work on it yourself, YOU DO SO AT YOUR OWN RISK.  Be safe, disconnect battery and wait at least 5 minutes to reduce, not eliminate, chance of accidental airbag deploy.  Do not use any test equipment while part is still connected to van as this can also deploy airbags.

To change the ignition switch:

  1. Remove negative (black) cable from battery, then remove the positive (red) cable.  Dop not let red cable touch anything metal.
  2. Stop and wait 5 minutes (DO NOT SKIP, SEE AIRBAGS WARNING)
  3. Remove the 3 bolts at the bottom of the knee bolster and remove
  4. Remove the 2 bolts from left/right side the metal cover under knee bolster
  5. Remove 3 screws from lower steering column and remove only lower steering column
  6. Locate ignition switch and remove 2 screws from ignition switch
  7. Disengage ignition switch from actuator pin
  8. Unscrew wire harness from it
  9. Reinstall using exact opposite procedure

I suggest when reinstalling, test after screwing new ignition switch in.

Thats it!  Van works perfect.

APC XS 1300 UPS Using 2 AGM Batteries

My trusty APC XS 1300 UPS’s battery died and wouldn’t keep a charge anymore. I really like this UPS, so I wasn’t ready to give up on it yet.

Original Battery

I first set out to buy a replacement battery, APCRBC109, but at $109.00, it was almost as expensive as a whole new unit. The APCRBC109 is 2 SLA 12v 9Ah batteries, which means its 2 sealed lead acid 12 volt 9 amp hour batteries that are wired in series to product 24 volts.

An amp-hour in its basic idea would be you can get 1 amp for 9 hours or 9 amps for 1 hour at 12 volts each.

So, if we were to use the UPS at full power we can estimate how long the battery on the UPS would last. This would give a estimate to compare other batteries with. You can get the total rating from the specs, 780 watts. To figure out how many amps it will draw from the battery, use the watts formula:

Watts is voltage x amperage, w = v x a. Re-arrange it so a = w / v
780w / 24v = 32.5 amps

In a perfect condition (ignoring UPS electronics loss, heat, etc)

9ah / 32.5a = 0.277 hours

Or about 16 minutes run time at full power. Pretty good to protect against short power outages, but we can do better if we want.

Replacement Battery

I bought 2 AGM 12v 55ah batteries.

If I apply the same formula as above, I can calculate theoretical run-time.

55ah / 32.5a = 1.69 hours

Or about 101 minutes! That makes sense because our new batteries hold about 6.11 times more power (55ah / 9ah) then the old ones.

The batteries need to be hooked up in a series, or positive to negative, circuit to create 24 volts (voltage is added in series) in the same way the original batteries do.  The batteries wont fit into the UPS, so I picked up 2 battery cases from Amazon and a resettable fuse.  The fuse was tied in series with the batteries just in case too much power is being drawn.


You can run standard AGM batteries to increase run time.

Backyard Theater

I became interested in a backyard theater while camping. There was a guy there who had just a white sheet, DVD player and a projector. It was awesome, they (him and his family) sat by the campfire and watched movies all night. It reminded me of the old drive-ins, just watching movies in the night air.

After getting home, I set out to build a system of my own. I had a few basic ideas and must-haves.

  • Cheap – Get used or make parts
  • Portable – In case I want to take it camping or a friends house
  • Bright – I want it easy to see, even in the moonlight of a full moon
  • Simple – Easy to setup/take down

After spending about 5 seconds looking at prices of new projectors, it was clear that Ebay was the way to go. There were some great deals that could be had on Ebay, but like anything else, you need to do your research. With projectors, there are so many specs on them that it can make your head spin. I’ll go over the major ones to look at:

  • Brighness / Color Light Output – Rated in lumens, this is the amount of light coming from the projector. The bigger the better, but get at least 2000, anything less will seem dark and not work very well with other light, such as moonlight.
  • Resolution – This is the number of pixels that can be displayed. The higher the better, but I recommend at least 1024×768.

I found a Epson 3LCD LCD Projector PowerLite 85 H295A but it was listed as Non-Working/Parts and didn’t have a bulb in it, so I checked Ebay again to find out how much bulbs were and since they we cheap, I bought the unit.  After installing the new bulb, the unit ran perfect.

Next thing on my list was to create a video source for it since I didn’t want to lug around my DVD player everywhere I went.  My solution for this was to load up XBMC on the RaspberryPi and run my videos from there.  The only issue was the projector had a PC VGA input, so I picked up a 1080p Hdmi Male Input to VGA +Audio Output Cable Converter Adapter on Amazon.

For audio I needed something loud, so I used an old pair of computer speakers that had a amp and subwoofer built in.  It worked out perfect, the HDMI adapter had a 3.5 mm plug that plugged right in.

Last, but not least, I needed a screen.  I found Ron-Loc Budget Blackout Lining at Joann Fabric.  This heavy cloth reflects light well and prevents light from going through.  If you’re on a budget, a white sheet works well too.

Overall, I spent less then $200 on the system for those hot summer nights to watch our favorite movies outside.


Making a J-Pole antenna is very easy to do.  The antenna can be made from various materials, such as copper pipe or 300 ohm twin lead.

A – Long Section
B – Short Section
C – Feed Point
D – Gap

Fedora 19 firewalld

Fedora 19 came out and its quite nice, but I’m not used to firewalld, as I am an old school iptables guy. I struggled with it at 1st, but after googling a bit, I got it going.

To get a list of predefined services:
firewall-cmd –get-services

To temporally add a service that is already defined:
firewall-cmd –add-service=http

To permanently (save across reboots) add a service that is already defined:
firewall-cmd –permanent –add-service=http

To temporally remove a service that is already defined:
firewall-cmd –remove-service=http

To permanently (save across reboots) remove a service that is already defined:
firewall-cmd –permanent –remove-service=http

Never disable your firewall completely!

My Thoughts

I started this blog with the intentions of sharing my knowledge and, in general, helping others. We need to learn ourselves, that sharing of knowledge is good, and as a whole we will all be smarter for it, whether that’s in a family, company, country or whole world, as the situation determines the sharing.

I tend to do a lot of “projects”, as I call them, which basically is a way of learning new stuff and testing out ideas and theories. I love learning and reading about new things, I can’t get enough of it. A friend sent me an article about different professions and their attitude of reading a book and how software developers read a lot to learn new skills, that’s true, but everyone has the capability to do that, not just developers.

We need to educate the young people with science and math skills, as this is our future of mankind. We need to learn basic skills like soldering and using instruments, such as multi-meters and oscilloscope’s. These things will help with basic understanding of how things work and hopefully inspire greatness. Pick up a screw driver and take apart that broken VCR and try to fix it. If it’s broke, you can make it worse. Grab an book and teach yourself PHP.

I am a child of the 80′s and our 1st PC was a Tandy TRS-80, which I learned to write very basic programs for. That PC created my passion for computers. Maybe it was the Radio Shack 50-in-1 kit my parents gave me for Christmas one year that solidified my love for electronics. It could also be the high school teacher that inspired me with mechanical drawings and CAD. A very big influence was my parents and their DIY attitude, just being around that and watching that instilled my maker attitude. All things considered, every experience we have, every bit of knowledge we get, broadens our horizons and creates a toolbox of tools that we can use in the future.

I encourage you to join a hackerspace or HAM club. Right now, the world is going through a maker stage, so be a part of it. Take stuff apart, see how it works. Be inspired, design your own. Don’t be scared of technology, embrace it, utilize it and make it your own. The possibilities are endless!