You need to sign in to do that
Don't have an account?
Inbox Outbox
public class queuables implements queueable{
public void execute(QueueableContext q) {
Account a= new Account(Name= 'queuable account');
insert a;
}
}
trigger QueueableTrgr on Account (before insert) {
if(trigger.isBefore){
if(trigger.isInsert){
system.enqueueJob( new queuables(trigger.new));
}
}
}
Error:
Constructor not defined: [queuables].<Constructor>(List<Account>)
Constructor not defined: [quclass].<Constructor>(List<Account>)
I have questions kind of related to this code as below
Thank you guys for the reply.
1. I was wondering why we use conditional boolean context variables like isInsert, isbefore when we already mention the DML events (before insert) in the trigger parameter!
2. Can we track the queuable job progress from whithin the same trigger which invokes?
code help please
public class queuables implements queueable{
public void execute(QueueableContext q) {
Account a= new Account(Name= 'queuable account');
insert a;
}
}
trigger QueueableTrgr on Account (before insert) {
if(trigger.isBefore){
if(trigger.isInsert){
system.enqueueJob( new queuables(trigger.new));
}
}
}
Error:
Constructor not defined: [queuables].<Constructor>(List<Account>)
Constructor not defined: [quclass].<Constructor>(List<Account>)
I have questions kind of related to this code as below
Thank you guys for the reply.
1. I was wondering why we use conditional boolean context variables like isInsert, isbefore when we already mention the DML events (before insert) in the trigger parameter!
2. Can we track the queuable job progress from whithin the same trigger which invokes?
So we have to write a bulkify code that works for the single record as well as multiple records.
Because when you insert a record from User Interface, you can insert only one record.
But when you insert many records using a data loader, then your code should be working for all records which will be inserted by the data loader.
Thank you!
Regards,
Suraj Tripathi
All Answers
We use isBefore, after when there is more than 1 parameter in the trigger.
Suppose there are 3 parameters in the trigger code. Ex:- and now we need to call some apex when the trigger is working in insert and need to solve other conditions when we trigger fire's on update. Then how we will be able to differentiate the work. In these scenarios, we use this condition i.e isBefore, isInsert, isUpdate.
These condition helps trigger to specifically work on the process that needs to be done depending upon the situation the trigger is fired.
Now coming to your 2nd query i.e can we track the queuable job from the same trigger which invoked them.
No, We cannot track them as they are queued and when the processor is free the queuable jobs are executed.
And, hence their logs are also separately generated, i.e different log is generated when the queuable job is executed other than the trigger log.
Hope this will help you.
If this helped you please mark it as the best answer.
Thank you!
Regards
Suraj Tripathi
Thank you for the reply. It clears so many things for me.
Can you help me with the above code? I am getting the error mentioned above (constructor), I can't seem to figure that out.
Here is the link for your reference:-
https://salesforce.stackexchange.com/questions/246580/when-passing-in-a-collection-of-sobjects-to-a-queueable-what-values-are-used
If there is any confusion please mention.
If this helped you please mark it as a best answer.
Thank you!
Regards
Suraj Tripathi.
Do we usually pass collection of sobjects as opposed to just one record?
I understand asynchronous apex is for bulk operations among many but can't I insert just one record as opposed to a collection? I am confused.
So we have to write a bulkify code that works for the single record as well as multiple records.
Because when you insert a record from User Interface, you can insert only one record.
But when you insert many records using a data loader, then your code should be working for all records which will be inserted by the data loader.
Thank you!
Regards,
Suraj Tripathi