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
Garrett MillerGarrett Miller 

Can I write a trigger that adds a Fee Opportunity whenever an account's renewal date passes?

Whenever an account's renewal date passes, someone has to manually enter an opportunity for an annual fee. I want to create a trigger/workflow rule/proccess that automates this, but I am unsure what the best way would be. There is no risk of the opportunity not being "Won" as it is just a fee. 

Does anyone have a suggestion on how to write a trigger for this? Or, is ther a better way than writing a trigger?

Best, 

Garrett

Best Answer chosen by Garrett Miller
Shruti SShruti S
You can use a Process Builder to do this. Here are the screenshots that will guide you to create the Process - 
 
User-added image
Selecting the Object.
 
User-added image
Setting up the decision.
 
User-added image
Setting up the schedule.
 
User-added image
Creating the action.

Note : Please click on the images to view them larger.

All Answers

Shruti SShruti S
Please let me know how to know if an renewal date has passed or not.
Garrett MillerGarrett Miller

@Shruti S It would be a case of: 

If today's date is greater than Today(), then the Next_Renewal_Date__c has passed

If today's date is less than today, then the Next_Renewal_Date__c has not passed. 

Every time Next_Renewal_Date__c passes, it gets updated to the next year. 

For example, say Account - Garrett has a Next_Renewal_Date__c of 6/8/2017. When the Today() date becomes 6/9/2017, then my Next_Renewal_Date__c has passed and my Next_Renewal_Date__c becomes 6/8/2018. 

So basically, I would want a trigger that says. 

 

if (Next_Renewal_Date__c > Today() ) {
Opportunity RenewalFeeOpp = new Opportunity();
opp.CloseDate=date.today();
opp.Name='Renewal Fee';
opp.StageName='Closed Won';
insert opp;
}
Shruti SShruti S
You can use a Process Builder to do this. Here are the screenshots that will guide you to create the Process - 
 
User-added image
Selecting the Object.
 
User-added image
Setting up the decision.
 
User-added image
Setting up the schedule.
 
User-added image
Creating the action.

Note : Please click on the images to view them larger.
This was selected as the best answer
Garrett MillerGarrett Miller
@Shruti S Thank you! 
Garrett MillerGarrett Miller

Yeah don't worry, I will mark it Best Answer as soon as I finish implementing it. Do you have any idea if this will bypass required fields on my Opportunity object? In addition, do you know if this will make me the Owner of the Opportunity? 

Shruti SShruti S
Do you have any idea if this will bypass required fields on my Opportunity object? 
No, it will not bypass.

Do you know if this will make me the Owner of the Opportunity?
Yes, it will make you the owner.
Garrett MillerGarrett Miller

So I am having some issues implementing this. I have changed it to an immediate action in order to iron out the issues but I have a question about setting the fields for Creating a Record. I got an error, This error occurred when the flow tried to create records: MALFORMED_ID: Company Name: id value of incorrect type: "Pseudo Company Name Here"

This is in relation to the field circled in the picture below. My question is, do I set the Company_Name__c to the Salesforce ID from the Company that the Opportunity is tied to? When I first select Company Name as the field to add, it automatically assumes the Type is ID. 



User-added image

Garrett MillerGarrett Miller

Nevermind I figured it out. With the field Company Name I set:

Type = Reference

Value = [Account].Id

Garrett MillerGarrett Miller

@Shruti S 

I have a question about this if you have the time. Will this only create a new record if I make edits/changes to a record? Or will it happen atuomatically? I don't want to have to make any changes to a record in order for a new record to be created. 

I tried to create a pseudo time field, and set the time dependent action to 1 hour after the pseudo time field, but no new record was created.