Image by Gerhild Klinkow from Pixabay
Published with permission from Dan Appleman
People who know of my work in the Windows world sometimes ask me how I, a “real" programmer and former Microsoft MVP, could become so involved with Salesforce development. I thought I’d write a different kind of article highlighting one of the Salesforce platform features that I find compelling—and that makes Salesforce, for me, a serious platform for software development. Instead of the usual "dry" technical article, I present to you a story - a work of fiction (except for the technology, which is all true).
My housemate’s voice just barely infringed on my attention. “They deleted a field!” he yelled.
It wasn't enough to distract me from my latest binge-watching effort.
“THEY DELETED A FIELD!”
The second time I couldn’t ignore him. I turned around to find quite a sight. He was on his feet shouting at the screen. Worse yet, he disturbed the cat, who decided I was the safest refuge. I reached for another allergy pill. Why we got a cat given my allergies, I have no idea.
“What’s going on?” I asked, trying to sound supportive. We’d both been working from home, sheltering in place for several months now, and I counted myself lucky—we still got along. Still, better him shouting at some remote miscreant than at me. “Who deleted what?”
He took a deep breath and explained. “Part of my client’s application went down yesterday, and they’ve been yelling at me to fix it,” he started. “It uses an Object Relationship Mapping library to make it easy to code against the database, and I was thinking it might have changed during a recent update. But it turns out that one of the client’s DBAs decided that a particular database column was no longer needed, and removed it.” He shook his head. “I just can’t believe it.”
Okay, I’m a nice guy, but I couldn’t resist.“I can’t believe it either – it has to be something else. You can’t delete a column that’s in use.”
“Of course you can’t, that’s why it failed,” he explained.
“No, you can’t," I said. "It’s not possible. If the column is in use, the database won’t let you delete it.”
Now he looked at me like I was crazy. Well, crazier–both of us were now three months without a haircut, so looking crazy was becoming the new normal.
“What do you mean the database won’t let you delete it?” he asked. “The database doesn’t care what you delete. It’s a database.”
I decided to be stubborn for just a bit longer. “You yourself said you were using an ORM library–so yes, the database should know the column is being used. After all, you’ve defined the objects and fields that map to the tables and columns–so the information is available. Right?”
He was just about to tutor me on the basics of application architecture when Angie appeared on the large screen. We met Angie in college, and she’s not just a friend–she’s also our go-to person for really sticky technical challenges. We’re both good at what we do, but bottom line–she’s better. We’d gotten into the habit of leaving an open Zoom connected to the large screen TV during the workday so she could drop in any time. It let us maintain some of that casual, walk over and chat at random times interaction that not only made the day more fun, but resulted in some of our best ideas.
It also let her play her traditional role of technical referee, which was what we needed now.
My roommate explained the situation to Angie: “My client’s application crashed because a database administrator deleted a table column.” He paused, gesturing at me. “This—person—is telling me that it has to be something else, because since I’m using an ORM, the database would block column deletion.”
I leaned back with what I hoped was a serious look on my face. Angie looked at me. Then she looked at my roommate and rendered judgement.
“He’s messing with you.”
“What?” my roommate asked.
“He’s messing with you–he knows what a traditional ORM system does. It serves as a bridge between code and a database – allowing you to code against database tables and columns using classes and properties in your programming language. It also creates methods on those objects that makes it easier to perform your CRUD operations.“But you know…” She glared at me. “ORM systems are a bridge. Some of them can create database schemas for you, and can even detect inconsistencies between the mapping and the database – but I don’t know that any of them can prevent a DBA from dropping columns or tables. They just don’t enforce data integrity on the database side.”
My roommate looked at me with a grin of smug satisfaction.
I quickly joined the Zoom and shared a screen. “Let me show you what I’m working on – it’s a project on Salesforce. Here’s an object.” I showed a custom object I had created. “We call it an object, but it’s really a database table. And the fields are the columns.”
I brought up a code window. “Now here’s how I can reference objects and fields in code.”
My housemate looked closely. “That looks like what I expect code to look like when using ORM …” He paused. “But how did you set up the mapping?”
“Magic,” I replied.
He gave me a dark look. “It’s software, not magic. Seriously, where do you set it up?”
I stood up, waved my arms mystically, and chanted, “Object obviat relationis tabularum faciendarum,” in my best wizardly voice.
“He’s messing with you again,” Angie said. “It’s automatic isn’t it?”
“It is.” I nodded. “Create a table, create a column, and it appears as objects and fields in the code instantly. You can query directly in code as well.”
“That’s pretty cool,” Angie said. “I haven’t looked at Salesforce as a platform–I thought it was just a CRM”.
“Yeah, it used to be,” I replied, “but it hasn’t been just a CRM for years. Let me show you something really cool.”
I went back to the object editing page, brought up a list of fields, and clicked on the option to delete a field. “Watch what happens when I try to delete a field.”
“See,” I continued. “I wasn’t kidding. At least on the Salesforce platform, if you have a static reference to an object or field–that is a table or column—the platform won’t let you delete it. It enforces data integrity. Really helps with reliability and stability…and situations like this.”
My housemate sighed. “That would be nice–but isn’t much help to me now.”
I nodded sympathetically. “Yeah–sorry about that. I just couldn’t resist.”
Angie had a thoughtful look. “Not just a CRM anymore, eh?”
My housemate shrugged. “It’s going to be a while before I have time for that,” he muttered.
“Here, this will cheer you up.” The cat gave me an annoyed look as I pushed her off my lap. I sniffled as she crossed the room, jumped onto my housemate’s lap, and started purring. My housemate calmed down as he started petting her and turned back to his screen. Maybe getting a cat was worth dealing with the allergies after all.