function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
cdaviscdavis 

Update to custom object upon sale of a gift card...

Hey everyone...

 

I've got a little problem that is really throwing me a curve ball. So, I have two custom objects, one for my product, and one for a gift card that can be purchased with my product (or skipped over, if no one wants to purchase it.)

 

I have a rule in place that determines whether or not a gift card is purchased with my product, and if one is, I want to update the quantity of my gift cards in stock.

 

Now, to determine if there is a gift card purchased on the Product object, I have a workflow rule that looks like this:

NOT( ISBLANK( Cards_in_Stock__r.Gift_Card__c ) )

 ** The "Cards_in_stock" callout was a lookup field that I created so that I could access the other object, otherwise I couldn't even see the fields in the Product object. 

 

When that workflow rule returns a "TRUE," I want to update my "Quantity in Stock" field on my gift card object. That's where it get's tricky. So, as a field update attached to the workflow rule above, I typed in this:

 

IF( NOT( ISBLANK( Cards_in_Stock__r.Gift_Card__c ) ) , Quantity_In_Stock__c - 1, NULL)

 

Well, that didn't do anything at all... so I tried this:

 

IF( NOT( ISBLANK( Cards_in_Stock__r.Gift_Card__c ) ) ,( (BLANKVALUE) Quantity_In_Stock, Quantity_In_Stock-1),

NULL)

 

That also didn't work. So, I went with a potentially simple solution:

 

Quantity_In_Stock__c - 1

 

 

That also did not work. Now, I'm out of ideas, and could really use some help. Anyone?

goabhigogoabhigo

Interesting...

 

Can you give more detail about the relationship between all 3 objects?

cdaviscdavis

Absolutely, I'll explain further...

 

Cards (greeting cards, thank you cards, etc...) are ordered through my storefront by customers, and their orders are disperssed into Force.com. I have a custom object, entitled "Letters," that all of the orders are displayed in. In this object, I can manage all my orders, and fullfil them. 

 

Now, when purchasing a card on our storefront, customers have an opportunity to include a gift card with their card. If they do include a gift card, it adds the gift card information to my Letters object that is created when the order is finalized. All of the individual gift cards (information about the card, vendor name, cost, etc... ) are stored in their own seperate object, called "gift cards." 

 

On the "Gift Card" object, there is a "Quantity in Stock" field that displays how many of each gift card are available. What I am trying to do is remove the gift cards from visibility when their Quantity reaches "0." All of the visibility workflow rules work fine, I'm just trying to update my "Quantity in Stock" field whenever a letter order is placed that includes a gift card. 

 

On the letter object, I have a lookup field called "Gift Card." If a customer orders a gift card along with a letter through my storefront, the gift card name is displayed in this field. Unfortunately, I had no way to access the Letter object FROM THE gift card object, so I created a lookup field in the Letter object that is tied to the Gift Card object, and named it "Cards in Stock." This field allows me to access Letter fields when writing Gift Card workflow rules. 

 

I've been attempting to use that as my determing factor for updating the "Quantity in Stock" field. Here's the type of workflow rule that I've been trying to write:

 

Rule: NOT(ISBLANK(Cards_in_stock_r.Gift_Card_c)) 

* This rule checks if there is a gift card purchased by verifying if the "Gift Card" field is blank on the Letter Object. 

 

Field Update: Quantity_in_Stock - 1

* I've tried a ton of these. This seems to be the one that should work... This Field Update happens when the Gift Card field IS NOT blank. It should subtract one from the overall total of the "Quantity In Stock" field on the gift card object.... but it doesn't. 

 

Any ideas?