Sunday, 9 August 2015

Migration In Salesforce.

Hello everyone, It's been a long time since I published my last post. But this time I came up with very interesting topic,Migration. We all know that migration in salesforce is not that much easy. But if we have proper knowledge about it then it wont cause any problem at any level. Then lets get started.

What is Migration?


Traditional definition of migration is "seasonal movement of animals from one region to another." The same definition is applied for salesforce too. 

In salesforce instead of animals there will be the development or customization which would be done by developer or admin. And instead of moving from one region to another region, We have to move it from one org to another.

See!! Migration is the same in real life as well as in salesforce.

Now, let's see what are the ways to do migration in salesforce.

1) Using Eclipse
2) Using Change-sets
3) Using Force.com Migration tool

I'll explain each and every technique one by one.

1) Using Eclipse


Eclipse is an integrated development environment(IDE). It contains a base workspace and an extensible plug-in system for customizing the environment. Written mostly in Java,Eclipse can be used to develop applications.

Eclipse is also providing force.com plugins, You must have to install that plugins in order to perform migration. 

After installing force.com plugins, you have to create new project in force.com and export the whole org. 

Now you'll see all the metadata are exported in eclipse at left side outline. From that list of metadata you can choose the component that you've to migrate. That component could be anything like class, pages, field update, workflow rules etc.

I'll give you example of migrating object from one org to another. Then you can migrate any component using this technique.

Here I've created one object named Object A in my personal org and trying to move another org. I've already exported my personal org in eclipse.






- Now right click on that, choose Force.com then click on deploy to server. Following is the snippet of that.




Now, You'll see the following screen and put the username and password of the destination org where you want to migrate everything. For ignoring to add security token, you also have to add ip address into that destination org.




After adding username and password, click on next. You'll see now the following screen. In that you've to add Directory then click next.




You can see following screen which will show the component that you're migrating. You can also validate that component on clicking validate Deployment button. Then click Next.





If you see the following message then congratulation, You've successfully migrated one object from one org to another org.





Click Finish. And you're done.
You can migrate everything using the below process.

2) Using Change-sets


Migration using change sets only works if you are migrating from sandbox to production. Migration using change sets is the easiest way to do migration.

For migrating using change set from sandbox to production, You've to logged in to sandbox first then go to setup >> outbound change set.

Add name to that outbound change set and add description just to understand that what are you migrating.

Then you'll be asked to add components from available components. You can add anything from available components. 

There is one thing that you have to take care if you're migrating classes using change sets then each and every class must have their test class also included into change set. All over code coverage must be more than 75%.

Once you've added all the components in outbound change sets then upload it. It'll be uploaded to production.

Now login to production. Go to setup >> Inbound change sets, There you'll be able to see the same change set which you've uploaded into sandbox. click on that change set.

Now you can see two buttons, one is Validate and second is Deploy, It's always best practice to validate your change set before deploying. So if there would be any error then you'll be informed before deploying,

After you've validated your change set successfully then you can deploy it to production.

I'm very sorry that I am not able to show you guys snippets/screenshots for this because it require sandbox and production org. Change sets are not available in developer org. But I hope this will help you. And If you guys face any problem in this topic then feel free to write your comment below.

3) Using Force.com Migration tool


Migration using force.com migration tool is little difficult but it'll make your task so much easy if you want to do continuous integration. Continuous integration in the sense that you'll be given a fresh set of orgs and you have to migrate same thing in each and every org. Then this tool is very helpful. 

When I came to know about this migration tool, I had a question by myself that why do we need this tool if we can migrate everything using eclipse but then I know, eclipse is more user friendly, but for continuous integration it's not best option.

We can schedule migration in force.com migration tool. Force.com migration tool is nothing but the ANT tool which is java based migration tool for salesforce. Let's get started then how to use ANT tool for migration.

Prerequisites  :  - JDK 1.5 or above
                        - ANT version 1.6 or above

For checking that JDK is installed in your system or not, you have to check in command prompt. Click Start, write cmd and open it.

Write "Java -version" in command prompt. if it shows the o/p like following then java is installed in your system.



If you do not get the given o/p then JAVA is not installed in your system. For installing java, please go to following link.


Now for checking that Is ANT installed in your system or not, Follow the same steps to the command prompt,  but instead of writing "Java - version" you've to write "Ant -version." And check that your o/p matched with the following screenshot or not.



If your o/p doesn't match with the given o/p then please download the ANT from following link.


Now unzip the file which you've downloaded and set Environment variable. I would prefer that you should set it in the existing environment variable where you set the java environment variable. The path should be parent folder of "bin",Also add the "bin" folder to your path. Let me show you the snippet of setting variable.




Now copy that address and paste it just after the path in environment variable where you've set the java path. Like following.

" C:\Program Files (x86)\Java\jdk1.6.0_22\bin;C:\ANT\apache-ant-1.9.4\bin\;" 

Now you've successfully installed the Ant in your system.After performing this, check again in command prompt that does ANT tool is installed in your system or not.

Now we can start the original process, Migration using force.com migration tool. There are two terms that you've to keep in mind for doing migration using this tool. One is source org, and second is destination org.

Source org is the org from where we want to migrate everything, while destination org is the org at where you have to migrate everything.

In terms of starting migration, you've to install force.com migration tool from your org. For that go to setup >> tools. There you'll see "Force.com Migration tool".




Zip file will be downloaded once you clicked on that force.com migration tool. Unzip that file and you'll see it contains three items. one folder and two files. which are Sample(Folder), Readme(File) and ant-salesforce(File).

Now you've to copy ant-salesforce file and paste it into lib folder of ANT (where the ant is installed).

Go to Sample folder >> unpackaged. There you will see file named package. Another concept came here which is XML. This file is nothing but the package.xml. In that you've to add each and every component manually. Which I'm going to explain how.

Given below code is nothing but the package.xml file when you open it for the first time.  You can see that there are only two types mentioned in this code, Apex class and Apex triggers. 

In the <name> tag, we've to specify which component do we need to add. 

While in <member> tag we've to specify the api name of that of component which we specified in <name> tag.

Let me give you example here, I created one class, page, object and trigger in my personal org. I'll show you how to migrate that from one org to another. For that we need to add that components in package.xml. Following are the components API name in my personal org.

Class name : Accounthandler
Page name : ExceptionPage
Object name : Test_Object__c
Trigger name : AccountTrigger


Save this file, One part is over, Now you have to go to sample >> build.properties file. you can see sf.username and sf.password, there you've to set your source org username and password. Add sf.serverurl as per your requirement, if it's developer or production then choose login.salesforce.com else if it's sandbox then choose test.salesfoce.com. Now save it.


Open command prompt, go to the directory where you extracted the force.com migration tool. Like I've installed it in drive D >> Deployment >> test. So my command prompt would be like given below. Write "ant retrieveUnpackaged" command there. Once the components will be retrieved it'll automatically create one folder named "retrieveUnpackaged".




Once we'll run the command. It'll show the status. See the following snippet.




Now we've successfully retrieved all the components from the source org which we added in package.xml file. You can cross check it in "retrieveUnpackaged" folder. As you can see in my "retrieveUnpackaged" folder which is given below.




Now you've everything in your system which you want to migrate. Again go to build.properties file and remove your source org credentials and add the destination org credentials, Don't forget to add sf.serverurl of destination org.


Now follow the same process which you've performed in retrieving data. Again open command prompt and go to sample directory. and write "ant deployUnpackaged" command and press enter.




Congratulation, You've finished your first migration using ANT/Force.com migration tool.

Notes :- 

- If you're facing any problem while retrieving or deploying components then you've to set your ip address according to your source org or destination org. Like if you're facing issue while retrieving then set ip address in source org and if you're facing issue while deploying then set ip address in destination org.

- For continuous integration, ANT tool is the best tool. You just have to prepare your package.xml file. I'll give you example of package.xml file which contain almost each and every component. So it'll help you to create your own package.xml file.

Following is the example of package.xml file which contains almost each and every component of one ordinary org. You can prefer this file for creating your own package.xml file.



The example which I gave you shows only few components but ANT is much more than that, We can schedule our migration even we don't have to look out for any dependencies if they're mentioned package.xml file.

Finally You've reached to the end of this topic. I know this topic is a bit lengthy but worth to read it. I hope this will help you guys, Next time I'll come up with more interesting and helpful topic. If you've any doubts then you can ask me in comments. Kudos. :)

Friday, 15 May 2015

Wrapper class in salesforce

Hello everyone, It's been so long since I posted my last post. I was little busy. Anyway, today I'm going to explain and show you all that what is wrapper class and how to use wrapper class in salesforce. And of course, how should I leave without giving example. So let's begin.


First of all, What is wrapper class?


- We all know that in salesforce it's quite easier to show only one objects data in visualforce page by using "pageblocktable" or "datatable". 

- But what if we want to show two objects data into table which has no relationship with each other. 

- Well, In that case we have to create one class that contains both of the objects and by using that wrapper class into our pageblocktable or datatable, we can access both of them objects fields.

- Above content was written as per my understanding. But as a definition wrapper class mean 


"A wrapper or container class is a class, data structure, or an abstract data type whose instances are a collections of other objects.It is a custom object defined by Salesforce Developer where he defines the properties of the wrapper class."

- Now I'm going to show you how to use wrapper class in salesforce. In this example I'll create one visualforce page which contain all the accounts and every account will have one checkbox. Here is the thing, that checkbox in front of every account record can be achieved by wrapper class, let's start the example for giving you all broad idea.

Page Code : 

      



Class Code :




OutPut :

 


After selecting some records.


So this is how it's done. I hope you guys understood what the wrapper class is and what is the use of it. Next time I'll come with more interesting and helpful topics. Until then have a nice coding. :)

Sunday, 15 March 2015

Best Practice for writing Triggers

        Hello everyone, Today I'm gonna give you some tips for writing triggers. First of all, What does it mean of Best Practice? It means that it's the ideal way to write triggers.

So let's get started with Best Practice for writing Triggers.
.
Since the day I wrote my first trigger,  I have written thousands of triggers. In this blog I'll discuss what should be taking care of while writing triggers and what could we avoid in that.

- Triggers are always executed when some DML event occurred like insert, update, delete, upsert, undelete etc.
-  It would be good practice in writing triggers that we can put all the trigger logic into some other class and call that class from trigger.
- So our trigger will contain only 2-3 lines of code which calls the method of that particular class which has trigger logic in it.

This would be more clear if I give you one example here.

- Assume that I created one custom field named testName__c of string datatype in standard object Account. Now I need that field to be populated whenever new account is created and that field value should be updated from account name. So the trigger for fulfilling that requirements is following.


Trigger Code :


Now, This trigger is very short and simple. Sometime you need to write a trigger which contains very complex logic and more lines of code. In that case, It's not best practice to write a trigger logic in trigger.

Following is code for the same trigger after moving its logic into class.


Trigger Code :



Class Code :


We saw that how to write trigger logic into class. But there is something more important that needs to be taken care of while writing triggers. And that is :


- DML
- Nested For Loop
- SOQL query


As we know that salesforce has some governor limits, That means, we can't use more than 100 soql queries and many more limitations like that. For avoiding some errors and taking care of this governor limits, we must have to take some precaution while writing trigger code.


1) DML statement is very important in trigger. Most of the triggers are written for bulkified operation. So, while writing trigger, we must have to take care of that we don't use DML operation in for loop or it can't be executed more than one time.

Following is the example. We consider the example which is given above. But instead of before, we'll use after insert. So we can use DML statement. It's just for understanding.

Trigger Code :


Class Code :


Now, here we used "update" operation in for loop which is highly unaccepted in trigger practice. This will definitely give you error if the list of account would be more than 100. What's the best practice then for using DML statement. Following code is improved code. Please look at it.


Trigger Code :


Class Code :


You can see what I did here. I made one empty list of the data-type list then just simply add all the accounts in that list which needs to be updated. And then simply applied DML operation for that particular list out of for loop.

2) Nested For loop is also not a good solution for trigger. 
- Although some developers use nested for loop in trigger. But I'll suggest not to do so. 
- If you do not find any solution for the problem and the only way to solve it is by using nested for loop, only then and then you can make a exception by using nested for loops. Otherwise find other ways to solve it. 
- I'm not showing any example for this but I hope you get my concept.

3) SOQL queries are very important while using trigger. 
- Queries can be used in most of the triggers. But as I mentioned earlier that salesforce has some of its limitations. SOQL query is one of them.
- We can't use more than 100 soql queries for one organization. So that's the best practice to use minimum soql queries. 
- But we get into trouble when we wrote only one query but it's been executed more than 100 times, that'll create problem for us. 
- You can guess, how is it possible that one query can be executed more than 100 times! 

Yes, you guessed right, In for loop. If we use soql query in for loop then it'll definitely give us error. 
For avoiding this kind of problem, create one list out of for loop and then fill that list up by using that query and use that list in for loop. That's the best practice.


Trigger Code :

Here we can see that query is being used within for loop so everytime it comes for new record, a query will be executed. For avoiding this, Check the following code.


Trigger Code :

At last, I'll give you summarized topics on which you have to look after while writing triggers.


- There should only be one trigger for each object.
- Use a consistent naming convention including the object name (e.g., AccountTrigger)
- Avoid complex logic in triggers. To simplify testing and resuse, triggers should delegate to Apex classes which contain the actual execution logic.
- Trigers should be "bulkified" and be able to process up to 200 records for each call.
- Use Collections in SOQL "WHERE" clauses to retrieve all records back in single query
- Bulkify any "helper" classes and/or methods.
- Execute DML statements using collections instead of individual records per DML statement.

I hope this helped you. Next time, I'll come up with more interesting and helpful topic for you guys. Till then, Have a nice coding. :)

Tuesday, 24 February 2015

How to avoid recursive triggers?

Hello Guys, Few days back, I was working on triggers and faced one problem that too many soql queries. But in real, I didn't use more than 2 queries in trigger. That mean the trigger was calling itself by more than one time. In other words it was recursive trigger.

So today, I'm gonna show you that how to avoid recursive triggers.


First of all you have to make sure that your trigger is executed just one time. For doing this, you have to make one class and add static boolean variable with default value true in it.

In the trigger, before executing your code keep  a check that the variable is true or not.

Once you check make the variable false.

Following is the code for that.

Class Code :



Trigger Code :


See, It's this much easy to avoid recursive trigger. I hope this will help you all. See you all guys later with some new problems and solutions.

Sunday, 15 February 2015

Quote To Cash Certification Answers (Fully)

1) What processes are included in the Quote-to-Cash umbrella?


a) Configure, Price, Quote
b) Contract Management
c) Billing and Order Management
d) All of the Above
e) Configure, Price, Quote AND Contract Management





2) What are the benefits of a streamlined quote-to-cash process?


a) Faster sales cycles and bigger deal sizes
b) More accurate forecasting
c) Higher levels of customer satisfaction and renewal
d) Reduced contractual risk
e) All of the above





3) What is NOT a step of the Quote-to-Cash process?


a) Configuration
b) Contract negotiation
c) Product design
d) Order fulfillment
e) Billing




4) Although Quote-to-Cash is an organization-wide initiative, which functional groups are MOST critical to the Quote-to-Cash process?


a) Operations, Finance, Marketing, Legal
b) Sales, Legal, Engineering, Executive-level
c) Suppliers, Sales, Legal, Finance
d) Sales, Legal, Operations, Finance
e) Marketing, Engineering, Sales, Accounting





5) Which organizational challenge is an indicator you need to fix your Quote-to-Cash process?


a) Restatements are a regular part of doing business
b) Marketing and Sales don't get along
c) Engineering creates duplicate product numbers
d) Contracts expire without anyone knowing
e) All of the above
f) Restatements are regular AND contracts expire without notice





6) When measuring the ROI of Quote-to-Cash, Sales Efficiency, Sales Effectiveness, Cost, and Risk are the primary categories you should look at.


a) True
b) False





7) A Sales executive might automate the Quote-to-Cash process to help his or her sales team improve their product knowledge when selling deals.


a) True
b) False





8) In the Gartner report, “How to Analyze Your Sales Processes on Efficiency versus Effectiveness,” which two tools rank the highest for improving sales efficiency and effectiveness?


a) Configure, price, quote, and sales incentive compensation management
b) Configure, price, quote and contract management
c) Contract management, and incentive compensation management
d) Configure, price, quote, and guided selling
e) None of the above





9) How does configure, price, quote (CPQ) support multi-channel sales?


a) CPQ increases partner visibility into product, pricing, and business rules so they know what to sell
b) CPQ provides full visibility into sales trends on a channel-specific basis
c) CPQ enables you to create channel-specific business rules for partners
d) CPQ tools offer role-based access, discount locks, and portals, so you can manage revenue share, e) exclusive discounts, or pricing and shipping fees
f) All of the above
g) CPQ enables channel-specific business rules for partners AND role-based access, discount locks, and portals





10) Warranties, manuals and third-party components can add complexity to the quoting process


a) True
b) False





11) Which is NOT a characteristic of an effective CPQ pricing tool?


a) Triggered approvals when reps sell bigger discounts than management has authorized
b) Options for creative discounts
c) Directs what approvals should kick in when reps go outside the preferred parameters
d) Control and streamlining supply chain operations with real-time visibility into inventory
e) Attribute based, usage based, and subscription pricing





12) What two drivers have to be balanced during the quoting process?


a) Opportunity and Contract
b) Speed and Control
c) Pricing and Configuration
d) Speed and Accuracy
e) Revenue and Margin





13) Pricing can be used to the modify behavior of customers and channel partners, but not sales reps


a) True
b) False





14) Pricing is the #1 lever you can pull to immediately impact revenue and margin


a) True
b) False





15) Why are contracts a critical part of Quote to Cash?


a) More than 80% of business transactions are tied to a contract
b) Insight into real revenue and costs can be found in your contract data
c) Your contracts contain data that is needed by everyone involved in the Quote-to-Cash process
d) Many businesses are moving to a subscription or services model that relies on repeat business with e) current customers
f) All of the above





16) Buy-side contracts are the primary focus for Quote-to-Cash


a) True
b) False





17) What are two challenges you need to balance for effective contract management?


a) Opportunity and Contract
b) Speed and Control
c) Pricing and Configuration
d) Speed and Accuracy
e) Revenue and Margin





18) Which is NOT a step in the contract management lifecycle?


a) Comply
b) Generate
c) Renew
d) Quote
e) Request
f) Approval





19) What role does Finance play in the contracting process?


a) Evaluates a contract’s financial impact and risks
b) Approves the commitment of resources per contract terms
c) Acts as the primary player during contract review, negotiation, and content assurance
d) Designs, creates, and maintains contract templates
e) All of the above
f) Evaluates financial impact and risk, AND approves the commitment of resources for contracts





20) Your business has a problem if more than 20% of contracts expire without notice


a) True
b) False





21) What are the four stages of contract maturity?


a) Hunting and gathering, grouping, committing, executing
b) Task automation, authoring, maximizing, performance enhancement
c) Consolidation, task automation, process efficiencies, contract performance
d) Co-termination, task automation, process efficiencies, performance
e) None of the above





22) What is the Billing Schedule?


a) A method of revenue recognition allowed by GAAP
b) A plan for recognizing revenue from an accounting perspective
c) A method of accounting which uses an accrual methodology
d) A plan for invoicing customers for products and services





23) What type of accounting is more complex


a) Cash accounting
b) Accrual accounting
c) They are equally complex





24) What is GAAP revenue?


a) Generally Accepted Automatic Payments
b) The revenue reported annually by GAP Inc to its shareholders
c) Revenue which is recognized in accordance with the standard accounting practices defined under GAAP
d) International Financial Reporting Standards





25) CDEF, the criteria that determine how revenue can be recognized, stands for:


a) Customer has accepted, Dollars are documented, Exchange is complete, Final payment secured
b) Cash on the table, Deliver the products, Expedite shipping, Fiscal impact
c) Collection is probable, Delivery is complete, Evidence of an arrangement, Fixed or determinable price
d) Contract acceptance rated, Deal documentation, Elevated price, Financial followup





26) Who is the Revenue team


a) The group of executive managers, including your CEO, CFO, and EVP of Sales, who are responsible to owners and shareholders for meeting the business’s financial objectives
b) The group of managers responsible for counting the cash at the end of each quarter
c) The partners responsible for conducting sales with your customers
d) The customers and prospects that bring revenue to your business
e) None of the above





27) Which is NOT a characteristic of effective Revenue Management?


a) Adopting cash based accounting
b) Automate and streamline the process with contract integration
c) Increase your executive management's team's visibility to revenue risks
d) Increase collaboration and eliminate bottlenecks across departments
e) Actively manage partner performance





28) Integrated contract management is an important characteristic of revenue management


a) True
b) False





29) The entire Quote-to-Cash process--including ecommerce capabilities and analytics, can be managed on Salesforce1


a) True
b) False





30) How do Apttus, Jitterbit, Adobe, and Xactly work together to streamline Quote-to-Cash


a) Apttus provides enterprise resource management on Salesforce1, Xactly offers CPQ, Jitterbit provides full revenue management and accounting software, and Adobe helps you bring all your agreements to the cloud.

b) Apttus provides full CPQ, contract management, and revenue management on Salesforce1, Jitterbit integrates your Quote-to-Cash with ERP, Xactly aligns your sales compensation with the behaviors that bring more dollars to your business, and Adobe speeds approvals for proposals and quotes with e-signature.

c) Apttus provides full CPQ, contract management, and revenue management on Salesforce1, Adobe allows you to make pdfs of sales agreements, Xactly helps you import your old contracts into Salesforce, and Jitterbit offers guided selling.

d) Xactly provides full CPQ, contract management, and revenue management on Salesforce1, Jitterbit integrates your Quote-to-Cash with ERP, Adobe aligns your sales compensation with the behaviors that bring more dollars to your business, and Apttus speeds approvals for proposals and quotes with e-signature.