Why do we program? To make machines what we what them to do. But machines speak in Binary language but humans don't.
Basic language is called machine language (eg punch card 1010101010)
Someone came up with idea > 'Hello Adam' <Compiler> 'changes to binary'
'Hello Adam' is a programming language and the first most successful was C
As program gets bigger next challenge was to make it manageable. Copy pasting code again again was not practical.
Next challenge how to make make multiple teams work on large program (& making it easier for ppl to think about it):
Sol: Functional programming and libraries
But programs became bigger, as next level challenge:
Sol: Object oriented programming (means think about it as real world)
& Design pattern (eg MVC, Decorator, Singleton) - This is mainly Architecture of the program - it is experience/framework (handle such problems in such a way)
Tip: Noun is a object, adjective are properties, verb is a function
Processes & rules:
Breathing Salesforce
Wednesday, April 24, 2019
Tuesday, March 13, 2018
External IDs and Http Mocks
Rest of the challenges for the "Apex Specialist" super badge were all right to handle. Relatively easier for me than challenge 1. Two key learning from my point of view:
1. In Salesforce you can use any field on the custom object to be used as an external ID. And, you can NOT set external id directly, i.e. code like MyObj__c.externalID = 'xyz'; does not work.
2. When testing a method that will make an http callout directly or indirectly, do not forget to set the mock class that implements HttpCalloutMock interface: Test.setMock(HttpCalloutMock.class, new MyCalloutMock());
1. In Salesforce you can use any field on the custom object to be used as an external ID. And, you can NOT set external id directly, i.e. code like MyObj__c.externalID = 'xyz'; does not work.
2. When testing a method that will make an http callout directly or indirectly, do not forget to set the mock class that implements HttpCalloutMock interface: Test.setMock(HttpCalloutMock.class, new MyCalloutMock());
Monday, March 12, 2018
Accessing Relationships with Apex
While attempting the first challenge for the Apex Specialist badge, I learned an important bit that helped me close the loop and finish the challenge successfully.
To access any related objects (look up, master-child), the API name that ends with __c is replaced by __r. For example, lets say class with name slave__c is under master__c, then an instance of the master class could access the slaves with syntax m.slave__r. Further, you can iterate through all the items with this syntax:
To access any related objects (look up, master-child), the API name that ends with __c is replaced by __r. For example, lets say class with name slave__c is under master__c, then an instance of the master class could access the slaves with syntax m.slave__r. Further, you can iterate through all the items with this syntax:
for(slave__c wp : m.slave__r){ //awesome code here }We can do something similar for lookup relationships. Note when the relationship is not one to many (as is with most look ups for the class doing the look up), __r yields a single object rather than a list.
Sunday, March 4, 2018
Effective JSON parsing with Apex
I am relatively new to Apex, but as a Java programmer the language does not feel alien. While doing a few trailheads to get me up to speed, I came across the Apex Rest Callouts module. While I was able to pass the challenge relying on the code snippet provided (here is my initial code), I was not convinced that it is the best way to parse a JSON response. And so began my search. Sharing my experience, just in case somebody finds it useful.
I first tried the developer reference, but totally struggled to make it work for the JSON I was working with.
My second port of call was JSON2Apex. And the answer was promising here, though it did take me some time to get to it. I would recommend the following steps for hassle free JSON parsing:
Step 1: Go to JSON2Apex application, paste your JSON, name your class and check the "Create explicit parse code" option. I don't do that initially and wasted a lot of time! You will get a zip file with a parser class and a test class. For the purpose of this post we will focus on the parser class. My parser class from JSON2Apex looked as linked.
Step 2: If you try to copy this into your developer console, the class will show an error as it has an inner class with the same name as the outer class!
Step 3: Use this parser to handle to JSON received from the callout. As you can see in the linked code, this is much more elegant and easier to code with, with all the heavy lifting done by the parser created by SFDC.
While this is done for a simple example, I am fairly confident that this can be done for complex JSON as well. Hopefully this helps you to simplify your JSON parsing and make your integration less painful!
I first tried the developer reference, but totally struggled to make it work for the JSON I was working with.
My second port of call was JSON2Apex. And the answer was promising here, though it did take me some time to get to it. I would recommend the following steps for hassle free JSON parsing:
Step 1: Go to JSON2Apex application, paste your JSON, name your class and check the "Create explicit parse code" option. I don't do that initially and wasted a lot of time! You will get a zip file with a parser class and a test class. For the purpose of this post we will focus on the parser class. My parser class from JSON2Apex looked as linked.
Step 2: If you try to copy this into your developer console, the class will show an error as it has an inner class with the same name as the outer class!
//not allowed in Apex! public class AnimalParse { //move the code inside inner class here public class AnimalParse { //get rid of inner class //after moving the code //some code, to move up } }Just take the content inside the inner class with the same name and move it up so that it becomes part of the top most class. Most probably it will be some member classes represented in JSON and a constructor for the outer class (as was in my case). For reference, linking my changed AnimalParser file.
Step 3: Use this parser to handle to JSON received from the callout. As you can see in the linked code, this is much more elegant and easier to code with, with all the heavy lifting done by the parser created by SFDC.
While this is done for a simple example, I am fairly confident that this can be done for complex JSON as well. Hopefully this helps you to simplify your JSON parsing and make your integration less painful!
Wednesday, August 3, 2016
SFDC: First Impressions
I spent some time familiarising myself with SFDC, and I present to you a summary of my initial thoughts after a week on SFDC from the perspective of a developer who has never used SFDC before.
General:
SFDC objects can have a "Master-Detail" relationship or a "lookup" relationship. This is not an object-oriented relation, but more like a relational database relation.
SFDC allows you to create custom views for the created instances, and can be assigned to specific users. This can be done in four ways:
Things I thought were really useful:
Things I thought can be made better:
Will update this article as my understanding gets better.
General:
SFDC objects can have a "Master-Detail" relationship or a "lookup" relationship. This is not an object-oriented relation, but more like a relational database relation.
SFDC allows you to create custom views for the created instances, and can be assigned to specific users. This can be done in four ways:
- Customising list of instances visible under a tab (after clicking on the tab, the "View" picklist on the top)
- The detailed information available when we click on a specific instance (modify using "Edit Layout" link). Within layouts there is an option to add specific related information for mobile devices by utilising "Mobile Cards" (applicable to Salesforce1 only)
- The mini page layout that comes up when you hover over a link (go to layout editor as in point 2, and click "Mini Page Layout")
- Creating specific compact layouts for mobile devices (option available in the object). Please note that compact layouts also determine which fields appear when a feed item is created
Things I thought were really useful:
- The "Schema Builder" can be extremely helpful as the org becomes increasingly complicated, and should be a good place to start when analysing a new org (especially when documentation. is thin)
- Multiple class instances can be created by uploading a CSV file. Therefore custom objects can be reverse engineered to seamlessly migrate excel data to SFDC. (Set up >> Import Custom Objects).
- Chatter puts a good spin on collaboration and alerting users about changes to objects. Users can also comment and share files. I think this would be much more productive than emails, and would provide a clearer audit trail if things go wrong. To enable mobile notifications: "Setup >> Salesforce 1 Setup >> Notification Option", and select "Include full content in push notifications"
Things I thought can be made better:
- The tutorial says that the layouts for custom views can be further customised for individual users for desktop, tablet, or mobile. This is not strictly true as views are simply assigned to users based on the anticipated use (e.g. if we expect a user to use mobiles, we create a specific mobile view for him and assign it to him).There is no "smart" view allocation which may allow SFDC to store and consider two different views for desktop/laptops and mobile devices. The application can detect the browser and select the view accordingly. This is something that I have done in the past for my web applications, and I think it may be a handy feature to have.
The double-edged swords:
- The system is very flexible and can be used in a zillion ways. However, this means that it can grow organically to become a complete mess/ nightmare to manage. This is expected as SFDC the product becomes less important than SFDC the platform. For the organization using SFDC it simply means tighter controls and documentation along with a clear understanding of the purpose of using SFDC. The flexibility means that you can use it to do a lot of things, though it may not always be the most efficient or economical way of doing it.
- I gather that SFDC is increasingly getting more complex, and would need more effort to integrate into a system. This means ultimately implementing it is going to become as expensive as SAP or any other complex ERP system. Not sure how this will play out. However it also means that it offers a great deal of flexibility in meeting business needs
I would use SFDC for
- Managing marketing and sales, including their traditional strengths of CRM, sales management, and service centres. Its flexibility means that the system can be modified to suit the exact needs of the system.
I would NOT use SFDC for
- Making application that need very fast, real-time response
Friday, December 19, 2014
Getting Force.com IDE to Work
Was exploring a bit of Force.com platform by Salesforce and started by setting up the Eclipse IDE. A few key things that I can point out are:
- Ensure both your Eclipse and the JDK are the same "bit" version (32/64)
- If you cannot get the "Force.com" perspective to appear, instead of adding a vm arg to eclipse ini file, set "JAVA_HOME" and "PATH" system variables on your machine: eclipse should pick it up. I have linked the documentation for setting PATH. You can use the same process for JAVA_HOME
Wednesday, November 13, 2013
Renaming Tab and Field Labels
Customise >> Tab names and labels.
Note: To change the name of field, do click on button 'Next' once you get an option to change the label of the tab. This usually gets missed and it seems that the link is only for changing the tab names.
Some useful SF links:
Renaming Tab and Field Labels
Considerations for renaming tabs and field labels
Note: To change the name of field, do click on button 'Next' once you get an option to change the label of the tab. This usually gets missed and it seems that the link is only for changing the tab names.
Some useful SF links:
Renaming Tab and Field Labels
Considerations for renaming tabs and field labels
Subscribe to:
Posts (Atom)