Which Tool To Use? Automate field update from old opp to a new created opp record - Answers - Salesforce Trailblazer Community
Ask Search:
Batir ChariyevBatir Chariyev 

Which Tool To Use? Automate field update from old opp to a new created opp record

Hey everyone.

I am working with a nonprofit. We have memberships that are renewed every year or so. Below scenario is on opportunity records (=memberships) that belong to the same contact record.

Scenario: Every time membership is purchased - the system creates new opportunities through a managed package. In some cases, members are renewing their membership before the end date of existing membership(opportunity). For that reason, I need to set a field value ending membership date of old opportunity to a new one when new opp is created. So that I can set the formula below to update field.

If correct info was on the same record this formula would work on flow.
IF( TODAY() < {!vOppRecord_Ass.npe01__Membership_End_Date__c}, ADDMONTHS({!vOppRecord_Ass.npe01__Membership_End_Date__c},12), ADDMONTHS(TODAY(),12))

My challenge is, getting a value from an old opportunity end date to end date of the new one. What tool I can use in such a case?

Appreciate your time and effort.
Best Answer chosen by Batir Chariyev
Tom HoffmanTom Hoffman
Ok, then you just need to swap out the AccountID for the Primary Contact field on the Opportunity (I assume thats the field if you are using NPSP).  

When your new Opportunity is created you would need to have a PB that calls a Flow (Critera would be like AND(ISNEW(), RecordType.Name = 'Membership')
For your action, that PB would pass the Opp ID into a record variable (we'll call this varNewOpp)
You would then add a 'Get Records' element where you are grabbing the Opportunity where Primary Contact equals varNewOpp.PrimaryContact AND Membership End Date > varNewOpp.MembershipStartDate and store that in a Text Variable like 'varOldOpp'
Last step would be a 'Record Update' action where you update the opp where ID matches 'varOldOpp' setting the your membership end date to 'varNewOpp.MembershipStartDate'

All Answers

Tom HoffmanTom Hoffman
Sounds fun - lets go for it. 

If I understand correctly, you want your Old Opps' Membership End Date to equal the New Opps Membership Start Date? 

I think this might work - I havent built it to test though. 

When your new Opportunity is created you would need to have a PB that calls a Flow (Critera would be like AND(ISNEW(), RecordType.Name = 'Membership')
For your action, that PB would pass the Opp ID into a record variable (we'll call this varNewOpp)
You would then add a 'Get Records' element where you are grabbing the Opportunity where AccountID equals varNewOpp.AccountID AND Membership End Date > varNewOpp.MembershipStartDate and store that in a Text Variable like 'varOldOpp'
Last step would be a 'Record Update' action where you update the opp where ID matches 'varOldOpp' setting the your membership end date to 'varNewOpp.MembershipStartDate'
Batir ChariyevBatir Chariyev
That's correct Tom. I have a 2 hours delay in the process mentioned above. So, the new process + flow when Opp created would possibly work on this case. Great idea. I am going to check it out in my Org. I will update in a couple of hours. 
Batir ChariyevBatir Chariyev
Hey @Tom Hoffman I have built the flow above. 

Process launches when membership type opportunity is created which triggers the flow. Below is a flow to get old opportunity. 

User-added image

Here is the one to set opportunity end date. 

User-added image


I am getting an error message below. 

FAST LOOKUP: Get_Old_Opp_Data
Find all Opportunity records where:
CreatedDate Less than {!varOppID.CreatedDate} (23/05/2019 2:28 AM)
ContactId Equals {!varOppID.ContactId} (null)
Sort records by: ContactId (Descending)
Store those records in {!varOldOpp}.
Save these field values in the variable: Id, npe01__Membership_End_Date__c, npe01__Membership_Start_Date__c, Name
Result
Successfully found records.

UPDATE RECORDS: Update_New_Opp_Date
Find all Opportunity records where:
CreatedDate Less than {!varOppID.CreatedDate} (23/05/2019 2:28 AM)
ContactId Equals {!varOldOpp.ContactId} (<varOldOpp.ContactId couldn't be resolved>)
Update the records’ field values.
npe01__Membership_Start_Date__c = {!varOldOpp.npe01__Membership_End_Date__c} (null)
Result
Failed to update records that meet the filter criteria.



 
Batir ChariyevBatir Chariyev
I believe my issue is happening here where it can't find a contact ID. 

Find all Opportunity records where:
CreatedDate Less than {!varOppID.CreatedDate} (23/05/2019 2:28 AM)
ContactId Equals {!varOppID.ContactId} (null)
Sort records by: ContactId (Descending)
Store those records in {!varOldOpp}.
Save these field values in the variable: Id, npe01__Membership_End_Date__c, npe01__Membership_Start_Date__c, Name
Result
Successfully found records.

Even though it says "successfully found records". I think it is not finding the right record. 
Tom HoffmanTom Hoffman
I'm confused? why is there a cotnact id involved? We are updating an Opportunity under the same Account with a value from another opp right? 
Batir ChariyevBatir Chariyev
@Tom Hoffman - Because we are working with individuals for memberships as I mentioned in the question. Opportunity is created by a third-party tool when the invoice is generated (via Managed Apex trigger) for membership purchase/renewal. 
Tom HoffmanTom Hoffman
Ok, then you just need to swap out the AccountID for the Primary Contact field on the Opportunity (I assume thats the field if you are using NPSP).  

When your new Opportunity is created you would need to have a PB that calls a Flow (Critera would be like AND(ISNEW(), RecordType.Name = 'Membership')
For your action, that PB would pass the Opp ID into a record variable (we'll call this varNewOpp)
You would then add a 'Get Records' element where you are grabbing the Opportunity where Primary Contact equals varNewOpp.PrimaryContact AND Membership End Date > varNewOpp.MembershipStartDate and store that in a Text Variable like 'varOldOpp'
Last step would be a 'Record Update' action where you update the opp where ID matches 'varOldOpp' setting the your membership end date to 'varNewOpp.MembershipStartDate'
This was selected as the best answer
Batir ChariyevBatir Chariyev
Thank you very much for your help, Tom. It worked out pretty well. 

Appreciate your time and effort!