Re: Set Custom Object with Opportunity Item

michaelstancil
Level 3

Set Custom Object with Opportunity Item

Hi all,

 

I'm trying to set a custom object to an email that is within an opportunity item so that I can use that newly set custom object to send a notification email via the flow step. This is because we send an email to a client with opportunity-specific info, and then we want to alert the sales rep of that email, but for other reasons, not all sales reps are on the lead level, so I need to surface them.

 

I've created a token that I've placed within the email that goes out to the client, and the referenced items are checked on the right, however, the values don't update. 

 

#set( ${OpportunityList.get(0).SalesRepEmail__c} = ${lead.CustomObjectEmail})

 

Any thoughts? 

Tags (1)
12 REPLIES 12
Jo_Pitts1
Level 10 - Community Advisor

Re: Set Custom Object with Opportunity Item

Are you expecting this to update back into the database?

If so, that won't work.  Velocity doesn't write back to the Marketo DB.

Regards

michaelstancil
Level 3

Re: Set Custom Object with Opportunity Item

That's exactly what I was hoping...as I was going to use that new field and perform a change data value. Are there any other ways around something like this?

Jo_Pitts1
Level 10 - Community Advisor

Re: Set Custom Object with Opportunity Item

I'm a bit bewildered here.

Are you trying to update the Sales Rep email on the lead or on the opportunity?

What if they have more than one opportunity.

 

i.e. can you explain the use case wrt opportunities and leads please

michaelstancil
Level 3

Re: Set Custom Object with Opportunity Item

Welcome to my world haha.

 

So we have Account and Sales owners, but because of how our system works they may get moved off to a variety of reasons and replaced with a catchall. Should that opportunity update to be valid again, the catch-all will remain on the account/sales level, but the in-opportunity fields will update with that correct info. 

 

It is very likely the sales reps will have multiple opportunities, so they would get multiple emails, one per unique opportunity (tied to a customer email, one opp per cust email)

 

The opportunity Owner (which does surface in the notification option) is there, but it's only their name. Is there some way to transform that field to an email?

SanfordWhiteman
Level 10 - Community Moderator

Re: Set Custom Object with Opportunity Item

@michaelstancil I’ll let you and Jo continue with the business requirements discussion, but be aware there are problems with this code on its own:

#set( ${OpportunityList.get(0).SalesRepEmail__c} = ${lead.CustomObjectEmail})
  1. Don’t use curly braces (= ${formal} = formal references) inside directives. Use $simple notation.
  2. I have not once seen code where it’s correct to simply use the first indexed Opportunity (.get(0)) . The Opportunity list must be treated as an arbitrarily ordered list. You should be targeting a specific Opportunity based on other characteristics, such as deliberately sorting the list by a Date field or checking other field values for the matching Opportunity.
michaelstancil
Level 3

Re: Set Custom Object with Opportunity Item

@SanfordWhiteman Thanks for the pointers, you made me realize I needed another value to key off of.

 

 

#set( $lead.CustomObjectEmail = "CATCHALL@EMAIL.COM" )
#foreach( $Opportunity in $OpportunityList )
#if( $Opportunity.VARIABLETOUPDATEAGAINST.isNotEmpty )
  #set( $lead.CustomObjectEmail = $Opportunity.SalesRepEmail__c )
  #break
#end
#end

 

 

Jo_Pitts1
Level 10 - Community Advisor

Re: Set Custom Object with Opportunity Item

@michaelstancil ,

this still won't work no matter HOW technically correct your code.. you can't update the lead from Velocity (hence why I didn't even get into to discussing coding with you).

 

I think you need a webhook to do this.  FlowBoost is probably a good option.

 

@SanfordWhiteman, can you see custom objects in FlowBoost?

 

Cheers

Jo

 

 

SanfordWhiteman
Level 10 - Community Moderator

Re: Set Custom Object with Opportunity Item

You certainly can.
michaelstancil
Level 3

Re: Set Custom Object with Opportunity Item

@Jo_Pitts1 gotcha, let me take a look!

 

@SanfordWhiteman (and Jo) if it WAS possible, would the revised code be correct at least?