Salesforce scheduled process reevaluation, or delete with trigger - salesforce

I have an order object with delivery date.
I have a process builder flow that runs when the date is > 14 days from today.
When it evaluates to true, it creates a scheduled process to run an apex class 14 days before the delivery date.
The above all works fine until i start changing the date. since you cannot use scheduled tasks unless you check the advanced option, now it wont reevaluate if the last time it ran it evaluated to true.
So if i change the date to a later date, the currently schedualed apex will still run 14 days before the original date, and not the new one.
Any workaround would be really appreciated.
I was thinking to have a trigger run on order update. If delivery date is changed then delete the process from que and then the process builder will reevaluate on its own. However i cant seem to find if thats possible.

I think this is a perfect scenario for a batch job, just put the process builder logic into a batch job and run it on a daily basis.

Related

Snowflake tasks are not triggered by schedule since 13h UTC the 16th of march

I'm facing an issue with my snowflake instance.
No tasks are running anymore. This suddenly happened.
I can run my tasks manually, but the automatic schedule is not triggering anything since 13 UTC today.
Do you have the same behavior ?
Thanks all
EDIT:
I have two tasks that are scheduled the same way (several times in a day), same schema, same user. One ran until 1h14 AM the other one ran all day long (as expected)
SOLUTION :
The only fix that I found was to recreate the task by doing and to make it run normally again.
To do so :
select get_ddl('task', 'TASK_NAME')
Execute the code provided by the query
Resume the task :
Alter task TASK_NAME RESUME
There was actually something, some of my tasks didn't resumed themselves after the snowplow bug fix : status.snowflake.com/incidents/jj1vgwvgxdqj
The only fix that I found was to recreate the task by doing and to make it run normally again.
To do so :
select get_ddl('task', 'TASK_NAME')
Execute the code provided by the query
Resume the task :
Alter task TASK_NAME RESUME
Thank you all for your help

How to check if no new opportunity has been created in past 1 year for an account in salesforce?

I've to create an automation process to check that no new opportunities has been created for an account in past 12 months and update the account field based on that.
Tried process builder, but it doesn't seem to work.
Tricky
A flow/workflow/process builder needs some triggering condition to fire. If an account was created 5 years ago, not updated since, haven't had any opportunities - it will not trigger any flows until somebody touches it.
And even if you somehow to manage to make a time-based workflow for example (to enqueue making a Task 1 year from now if there are no Opps by then) - it'll "queue" actions only from the moment it was created, it will not retroactively tag old unused accounts.
The time-based actions suck a bit. Say you made it work, it enqueued some future tasks/field updates/whatevers. Then you realise you need to exclude Accounts of certain record type from it. You need to deactivate the workflow/flow to do it - and deactivation wipes the enqueued actions out. So you'd need to save your changes and somehow "touch" all accounts again so they're checked again.
Does it have to be a field on Account? Can it be just a report (which you could make a reporting snapshot of if needed)? You could embed a report on account layout right? A query? Worst case some apex nightly job that runs and tags the accounts? It would dutifully run through them all and set/clear your helper field, easy to change (well, for a developer).
SELECT Id, Name
FROM Account
WHERE Id NOT IN (SELECT AccountId FROM Opportunity WHERE CreatedDate = LAST_N_DAYS:365)
Reporting way would be "cross filter": https://salesforce.vidyard.com/watch/aQ6RWvyPmFNP44brnAp8tf, https://help.salesforce.com/s/articleView?id=sf.reports_cross_filters.htm&type=5

Keep a look-out for passing dates, then take action "real-time"

Let's say I have a table with a date column; can I attach some sort of "watcher" that can take action if the date gets smaller than getdate()? Note that the date is larger than getdate() at the time of insertion.
Are there any tools that I might be unaware of in SQL Server 2008/2012?
Or would the best option be to poll the data from another application?
Edit: Note that there is no insertion/update taking place.
You could set up a SQL Job which runs periodically and executes a stored procedure which can then handle the logic around past dates.
https://msdn.microsoft.com/en-gb/library/ms187910.aspx
For example a SQL Job could be set up to run once daily to find out user's birthdays and send out an automated email.
In your case a job could be set up every minute (if required) which detects past dates and does something with those records. I would suggest adding some kind of flag to each record so that it isn't actioned the next time the job runs.
Alternatively if you have a lot of servers and databases, you could centralise your job scheduling using a third-party tool such as ActiveBatch.

Time Interval to execute trigger

I have trigger to delete records which execute after I change the status. Is it possible to delete the records after some 10 mins after I change the status.
10 minutes exactly im not sure, but you can delay it for an hour using time based triggers in a workflow rule.
In your trigger, instead of deleting a record, mark a boolean field "For Delete" as true, and make a worflow rule that, when that field is set to true fires a time based action 1 hour after workflow activation, marking a new field, "deleting" and a new trigger on the same object to delete any record that has that checkbox filled.
In addition to the other answer I'd like to point you to help related to batch jobs on salesforce. You could have a scheduled task running say every 10 minutes, checking if there's something to delete (and maybe lastModifiedDate is ealier than 10 mins ago) and wiping it out.
Or you can use System.scheduleBatch() call to put given job in the queue of future executions only once (so it wouldn't be running all the time, only when you queued it from your trigger).
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_batch_interface.htm

SQL Server trigger to update data automatically

I'm designing a library management database schema, let's say there is a table "Borrow"
Borrow
id
user_id
book_id
borrow_date
due_date
isExpired
expired_day (number of days after the book is expired)
fine
Can the SQL Trigger implement the following circumstances?
1.Compare the due_date with Today, if it's same-->send email-->mark isExpired to true
2.If isExpired is marked to true-->compare the difference between today and due_date, and update expired_day--->update fine (expired_days * 5)
A trigger only fires when something happens on the table or row. It won't fire continuously (or daily). If nothing happens to the table then your trigger will never fire so your checks can't be done.
So, the trigger you describe would work when you first insert a record into the row, but there's no automatic way with a trigger for it to fire after the due date period to check for the expiry and fine.
You would most likely need to setup a stored procedure that contained your code and find a way to run that on scheduled basis.
The following link goes over how to set that up:
Scheduled run of stored procedure on SQL server
Since you want to check all the records of the library daily and want them to be updated accordingly, it is better to make a daily job and schedule an agent and set a particular time so that this daily job would be executed everyday automatically.
pls Note : You should keep in mind to choose that time when you feel your application would be least used during the entire day.
Creation of Agent : http://msdn.microsoft.com/en-us/library/ms181153(v=sql.105).aspx

Resources