+ Start a Discussion
Thomas PanniThomas Panni 

Automatic Asset Creation on Opportunity or Quote close

Hi out there,
I an absolute Apex beginner and would like to solve a problem: Once an opportunity is closed won the products from that opportunity should automatically become assets for that customer. I know I need a trigger, a class and a test class. So in general my idea is as follows:

if opp stage = closed won
   and if opp has products
for each product (opp-line item) 
create asset
with account ID...
set asset name = product name

etc...

How can I solve this? Where could I find appropriate code samples? Any help is pretty welcome...
So thanks in advance...

best regards Thomas
Paul S.Paul S.
Hi Thomas - it appears you're on the right track as far as your thinking goes.  Have you tried writing any code for this?  

p.s. one place that might provide you some background learning is over at sfdc99.com (http://www.sfdc99.com/beginner-tutorials/).
RaoulRaoul
Hi Thomas,

I am looking to do exactly the same with one small change - I want to generate an asset for each line item when the quantity is >1. Have you had any luck with it as yet? I found an app on the appexchange that does almost everything I need, except this and adding a location in, so if anyone has any thoughts on the best way to code this would be appreciated - I also am very new to salesforce development, but have some coding experience, so hopefully the learning curve is not large.
VioletViolet
Have you tred visual flows? Where you able to make the Trigger work?
Grond1lGrond1l
Hi Thomas,

Have you had any luck with this trigger?

Thanks!
ClaiborneClaiborne
Look a little harder. There is a FREE app on AppExchange, uploaded in 2009 by salesforce labs - https://appexchange.salesforce.com/listingDetail?listingId=a0N30000001yKgpEAE. According to the description, "When an opportunity's status is changed to "Won," this application takes all associated products and places them as assets in the corresponding account."

There are a few problems reported in the review comments, but most people like it. Remember, there is not a lot of support for this, but it is easier than writing your own code.

Still, it may not handle everything correctly. For instance, you may have products that you do not want an asset for, say a product like Installation or Training. It would be good to create a check box on the product - Create Asset. Then assets would be created only products where the box is checked.

Another enhancement would be parent and child assets. The current code does not handle this at all.

But it is a good start.
Thomas Panni 6Thomas Panni 6
Hey Claiborne,
thanks a lot for that one. I will try it within the next weeks. It is a real good starting point. Let's see if I can handle or adopt the code in terms of the check box you suggest. Will let you all know...