Tuesday, August 17, 2010

Salesforce - Syncing a Quote in Apex

I've been working with Salesforce Quotes recently and overall I like the functionality. One thing that took me a little while to figure out, though, was how to sync a Quote with its Opportunity through Apex.

I spent a little bit of time looking through the Quote fields with Eclipse's 'Content Assist' feature, but the closest thing I was able to find was the IsSyncing field. I tried setting that to true but knew of the error message that was surely about to pop up, "Field is not writeable." Like other Salesforce Is*Action* fields, Quote.IsSyncing is read only and you cannot write to it through Apex directly. I then tried to find a built in method that duplicated the "Start Sync" button found on a Quote's layout page, though I found no such functionality.

So how do you go about syncing? The secret to syncing a Quote with its Opportunity lies not in the Quote's fields, but in the Opportunty's fields. A quick glance through those fields reveals a look-up relationship called SyncedQuote, and this field (actually SyncedQuoteId) is what allows us to sync a Quote. The implementation is easy, just a simple assignment:


// Begin syncing Quote with Opportunity. Same as pressing the "Start Sync" button on Quote layout
parentOpp.SyncedQuoteId = quoteToSync.Id;



If you want to stop syncing the Quote or start syncing a different Quote, you simply adjust the Opportunity.SyncedQuoteId field accordingly.

A limitation that I want to note is that the above code only works in an Apex Class, at least as of API Version 19. This means that you can sync a Quote through Apex in an standard Apex Class or an Apex Test Class, but not through an Apex Trigger. If you try to sync a Quote in an Apex Trigger you will receive an error message explaining this functionality.

41 comments:

  1. I got the same problem and I was just looking for such information. Thanks a lot.

    ReplyDelete
  2. Hi,

    I want to add some information. I was also working with this functionality. If you call a Class which is modifying the SyncQuoteID, and call it via a Trigger, you will receive the same error message. However, if you call the Class explicitly (eg. From Dev Console) and pass an existing Opportunity record ID, it will go through.

    Also, if you want to clone an existing Opportunity with an associated Quote Record in which Syncing is on, and then try to clone the Opportunity using Clone() from Apex, it will not let u through if you do it via a Trigger. The solution to this problem is either create a VF Page and write the functionality in Controller of that VF page and call it via a Button. Or, if this doesn't have to be real-time, then the same functionality can be created using Batch Apex and by making it schedulable.

    Thanks,
    Himanshu

    ReplyDelete
  3. Hi, I'm new programming apex and it would be really great if you could help me a little bit creating the function in the class to sync the opportunity-quote with a custom button.

    I have another question: do you know how its possible to overwrite the standard "view" layout of the quote. I can only overwrite the "edit" button with a visual force page but it doesn't work when I only want to "view" it.

    I hope you can help me,
    thanks Peter

    ReplyDelete
  4. Thanks a lot!

    ReplyDelete
  5. thanks for posting! saved me a lot of time.

    ReplyDelete
  6. I have another question: do you know how its possible to overwrite the standard "view" layout of the quote. I can only overwrite the "edit" button with a visual force page but it doesn't work when I only want to "view" it.

    Seo Job training

    ReplyDelete
  7. In coming years, cloud computing is going to rule the world. The cloud based CRM tool provider like Salesforce have massive demand in the market. Thus talking salesforce training in Chennai from reputed Salesforce training institutes in Chennai will ensure bright career prospects for aspiring professionals.

    ReplyDelete
  8. Web technology has evolved so much in the past years and it is being the part of a company's growth for a long time(Web designing course in chennai). It is explicitly printed in the above content. I really love the way you have started writing this article. It is the skill that every blogger require. Thanks for sharing this in here once again. Keep blogging like this(Web designing courses in chennai).

    ReplyDelete
  9. Latest Govt Bank Jobs 2016

    Every day I always visit sites to obtain the best information for materials research I was doing.....................

    ReplyDelete
  10. Really awesome blog. Your blog is really useful for me. Thanks for sharing this informative blog. Keep update your blog.
    Oracle Training In Chennai

    ReplyDelete
  11. I am reading ur post from the beginning, it was so interesting to read & i feel thanks to you for posting such a good blog, keep updates regularly.Best Hadoop Training Institute In Chennai

    ReplyDelete
  12. Nowadays, most of the businesses rely on cloud based CRM tool to power their business process. They want to access the business from anywhere and anytime. In such scenarios, salesforce CRM will ensure massive advantage to the business owners. Amazon Web Services Training in Chennai | Amazon Web Services Training

    ReplyDelete
  13. Nice blog. All the latest manufacturers drivers available for IVR Software Patch… ivr telephony

    ReplyDelete
  14. To keep ourselves up to date with the current trend is not an easy task in IT. But we can, through quality and worth able content like this. Thanks for sharing this web page. Please write more articles like this in future.
    PHP training in Chennai | PHP course in Chennai

    ReplyDelete
  15. The strategy you have posted on this technology helped me to get into the next level and had lot of information in it. The python programming language is very popular and most widely used.
    Python Training in Chennai | Python Course in Chennai

    ReplyDelete
  16. The usage of third party storage system for the data storage can be avoided in cloud computing and we can store, access the data through internet.
    cloud computing training in chennai | cloud computing courses in chennai

    ReplyDelete
  17. Amazing .. Thanks for giving me the useful information. I think I need it!
    happy wheels demo | friv

    ReplyDelete
  18. Amazing .. Thanks for giving me the useful information. I think I need it!
    العاب
    cooking games 2016
    al3ab banat 9

    ReplyDelete
  19. This comment has been removed by the author.

    ReplyDelete
  20. Run 3 unblocked is the third install of the Run Serie. Skate, float, bounce, and/or jump your way through even more space tunnels! Run 2 unblocked game is next games in run series, now you can play run game with more and more level. Try to run as far as possible, good luck. Tanks Trouble is a game designed by danish Mads Purup. It is a maze party game with 1-3 players on one computer. The objective of the game is to destroy the other tanks to get a point.
    Run 2 - Run 2 unblocked - Tank Trouble - Tank Trouble 2

    ReplyDelete
  21. Updating with the latest technology and implementing it is the only way to survive in our niche. Thanks for making me this article. You have done a great job by sharing this content in here. Keep writing article like this.
    SAS Training in Chennai | SAS Course in Chennai

    ReplyDelete
  22. Excellent post!!!. The strategy you have posted on this technology helped me to get into the next level and had lot of information in it.
    salesforce training in chennai | salesforce training institute in chennai

    ReplyDelete
  23. Excellent post!!!. The strategy you have posted on this technology helped me to get into the next level and had lot of information in it.
    oracle training in chennai

    ReplyDelete
  24. The blog or and best that is extremely useful to keep I can share the ideas. Age Of War 2
    Big Farm | Slitherio | Tank Trouble
    Of the future as this is really what I was looking for, I am very comfortable and pleased to come here. Thank you very much.
    Happy Wheels | Goodgeme Empire | Slither.io

    ReplyDelete
  25. Very interesting content which helps me to get the in depth knowledge about the technology. To know more details about the course visit this website.
    Digital marketing course in Chennai | Digital marketing training in Chennai

    ReplyDelete
  26. I ever had seen this information over the blog sites; actually I am looking forward for this information. Here I had an opportunity to read, it is crystal clear keep sharing…I have an expectation to see your upcoming post.
    Salesforce Training in Chennai|Salesforce Training

    ReplyDelete
  27. Such a very useful article. Very interesting to read this article.I would like to thank you for the efforts you had made for writing this awesome article.

    Discover our website bounty of free online games now!
    Our website has the biggest collection of free online games. Totally new games are added every day!

    age of war 2
    gold Miner 2
    unfair Mario 2
    cubefield 2
    tanki Online 2

    ReplyDelete
  28. The strategy you posted was nice. The people who want to shift their career to the IT sector then it is the right option to go with the ethical hacking course.
    Ethical hacking course in Chennai | Ethical hacking training in chennai

    ReplyDelete
  29. Pretty article! I found some useful information in your blog, it was awesome to read, thanks for sharing this great content to my vision, keep sharing.
    Regards,
    AWS Training | AWS Training in Chennai

    ReplyDelete
  30. Facebook has become a part of my life, not only helped me to connect with you but also where I can share every moment in life. I really like the convenience that it brings
    facebook baixar , baixar facebook , baixar facebook gratis

    ReplyDelete
  31. Life becomes more interesting and wonderful when you share your memorable moments with friends and family through unique photographs. You can create your own unique style impressed with image editing
    square quick , download square quick , square quick , square quick , square quick app

    ReplyDelete
  32. Thanks for sharing this information and keep updating us. This information is very useful to me.
    Ethical Hacking Course in Chennai | Hacking Course in Chennai | Ethical Hacking Course

    ReplyDelete
  33. Interesting and informative article.. very useful to me.. thanks for sharing your wonderful ideas.. please keep on updating..

    Oracle Training in chennai | Oracle Training institute in chennai

    ReplyDelete
  34. HI, pretty article, interesting to read this topic ,keep more update magento 2 training

    ReplyDelete