Thursday 22 August 2013

Understanding PriceBook, Product, and PricebookEntry Relationships

In the API:
  • Pricebooks are represented by Pricebook2 objects.
  • Products are represented by Product2 objects.
  • Each price book contains zero or more entries (represented by PricebookEntry records) that specify the products that are associated with the price book. A price book entry defines the price for which you sell a product at a particular currency.
These objects are defined only for those organizations that have products enabled as a feature.


price book is a list of products and their associated prices. Each product and its price is called a price book entry.
Salesforce provides two types of price books—standard and custom.
  • The standard price book is a master list of all products with their associated default or standard prices. It automatically lists all products and standard prices regardless of the custom price books that also contain them.
  • A custom price book is a list of products with their custom or list prices, making them ideal for offering different prices to different market segments. Custom price books can contain discounted list prices or list prices that are higher than the standard price.

PricebookEntry

  • Use this object to define the association between your organization’s products (Product2) and your organization’s standard price book or to other, custom-defined price books ( Pricebook2).
  • Create one PricebookEntry record for each standard or custom price and currency combination for a product in a Pricebook2.
  • When creating these records, you must specify the IDs of the associated Pricebook2 object and Product2 object.
  • You must load the standard price for a product before you are permitted to load its custom price(s).


Price Book Setup


The process of setting up a price book via the API usually means:

  1. Initially loading product data from your organization into Product2 objects (creating a Product2 record for each product that you want to add).
  2. For each Product2 object, creating a PricebookEntry that links the Product2 object to the standard Pricebook2. You need to define a standard price for a product at a given currency (if you have multicurrency enabled), before defining a price for that product in the same currency in a custom price book.
  3. Creating a custom Pricebook2.
  4. Querying the Pricebook2 object to obtain their IDs.
  5. For each Pricebook2 object, creating a PricebookEntry for every Product2 that you want to add, specifying unique properties for each PricebookEntry (such as the UnitPrice and CurrencyIsoCode) as needed.


Important Note:

  • PricebookEntry is a junction object between Pricebook2 and Product2.
  • OpportunityLineItem is a junction object between PricebookEntry and Opportunity.

Code Sample—Java


public void pricebookSample() {
  try {
    //Create a custom pricebook
    Pricebook2 pb = new Pricebook2();
    pb.setName("Custom Pricebok");
    pb.setIsActive(true);
    SaveResult[] saveResults = connection.create(new SObject[]{pb});
    pb.setId(saveResults[0].getId());

    // Create a new product
    Product2 product = new Product2();
    product.setIsActive(true);
    product.setName("Product");
    saveResults = connection.create(new SObject[]{product});
    product.setId(saveResults[0].getId());
    
    // Add product to standard pricebook
    QueryResult result = connection.query(
        "select Id from Pricebook2 where isStandard=true"
    );
    SObject[] records = result.getRecords();
    String stdPbId = records[0].getId();
    
    // Create a pricebook entry for standard pricebook
    PricebookEntry pbe = new PricebookEntry();
    pbe.setPricebook2Id(stdPbId);
    pbe.setProduct2Id(product.getId());
    pbe.setIsActive(true);
    pbe.setUnitPrice(100.0);
    saveResults = connection.create(new SObject[]{pbe});
    
    // Create a pricebook entry for custom pricebook
    pbe = new PricebookEntry();
    pbe.setPricebook2Id(pb.getId());
    pbe.setProduct2Id(product.getId());
    pbe.setIsActive(true);
    pbe.setUnitPrice(100.0);
    saveResults = connection.create(new SObject[]{pbe});
  } catch (ConnectionException ce) {
    ce.printStackTrace();
  }
}

Saturday 3 August 2013

Open Government Data Initiative: Discover > Participate > Engage > Innovate

Last week, I got an email from one of my colleagues and it caught my attention. It's worth sharing here.

NASSCOM with the support of Microsoft Corporation (India) Pvt. Ltd.  organized an Open Data Meet on 29thJuly, 2013 at Microsoft, Bengaluru to "Educate the Start-up & Developer Community on what Open Data exists and its accessibility".



Open data Initiative, a joint initiative of NIC and NASSCOM, where you can build apps for billion Indians on Open Data, some valuable datasets related to Health, Agriculture, Water & Sanitation, etc.



With the mission to promote transparency and greater citizen engagement in governance by making more government datasets/applications publicly available, the theme emphasizes on:

  • DISCOVER how power of Open Data can be harnessed for public benefit.
  • PARTICIPATE in discussions & exchange of information on enhancing the effectiveness of Open Data.
  • ENGAGE in identification of new Open Government Datasets and innovative projects around them.
  • INNOVATE ideas that catch fire, burn longer, and spread further.


In fact this initiative is world wide. See the worldwide data sites.

Socialize on this initiative:

Twitter_Logo.bmp                                              
Facebook_Logo.bmp


Friday 2 August 2013

Thinking of simplifying Salesforce.com with Google glass

Do you believe that a series of incident could lead you to something more interesting that you start finding the connections between them and finally analyze them to arrive at your own personal opinion.
Yes, I think everyone does.

Last week I came across a website CloudTweaks where there was a separate section Cloud themed comic library. One of the humors caught my attention to Google GlassSee what it does.





Later on I thought can we make cloud interacting with us.

Yes we have been  using Salesforce CRM with Google Apps. However, I wondered if Salesforce.com can be leveraged by integrating Google glass with SFDC.

What magic do you think that could be performed by bringing Salesforce CRM on Google glass.
For example, when both are properly linked, I see a person and I get his/her SFDC profile right in front of your glass. Isn't it a magic.

Lets have fun and share whatever such magic/scenario we can think of.

Thursday 1 August 2013

Lessons learned while working of Salesforce Web Services

My this blog is directly or indirectly associated to the Thomson Reuters internal blogs because whenever I was on low of my mood elevator while working on these QCs, these blogs have fostered me to try solving the error again and again.

This was the first requirement related to Salesforce Web Services on which I was working from the scratch. I encountered many problems, solved many errors and finally learnt many new concepts on the way.
One of such errors which made me go mad and challenging me everyday was :

System.CalloutException: Web service callout failed: Unable to parse callout response. Apex type not found for elementhttp://west.thomson.com/crm/rocketxsd/4.0/invoice=OpenClearedItems

It is torturing me mentally (being on low mood elevator) since last few days in succession and no progress was made. Lots of email exchange between Dev team and Web Service side, Code debugging and SOAPUI testing many number of times and what not we did. Never I had used Developer Console, Debug Log that many times in my work.

I am going to mention solutions/lessons which I learned while working on QC 3996(Accounts Receivable Data in S2E) & QC 3891(Invoice Image Capture Integration–IXOS) for August Release. With so much consistent and repeatitive effort, the QC finally signed off into QA environment today.


So here I am enumerating some of the concepts which I learned with regard to this QC.


First Learning

After raising a case with Salesforce.com support, this is the response which I got from Salesforce:

xsd:element In Apex code saved using API version 15.0 and later, the ref attribute is also supported with the following restrictions:

And in Invoice WSDL, I find ref being used at:


Later on WSDL was changed considering the limitations under which ref could be used.  Problem solved!

Second Learning

I wanted to open the document in a new tab on clicking commandLink on the VF page. However, it was not allowing me to do so.




  • Reason of the issue:
    • reRender attribute was not allowing to open the document in a new tab but in the same. reRender attribut was removed. Problem solved!

Third Learning

Extensive use of Debug Log, Developer Console, SoapUI for debugging and testing.

Fourth Learning

From Test Classes, we cannot give a Web Service callouts. So in order to cover those piece of code under WebServiceCallout.invoke(), using Test.isRunningTest() methods for getting mock web service responses would help in increasing the test class coverage.

Fifth Learning

More importantly, I get to learn the importance of Collaboration, Teamwork, Positive Intent, Mood Elevator et al. 

Have you ever come across any learning while working. Please do share with us.

 It has been a challenging learning with these QCs 3996 and 3891.