You need to sign in to do that
Don't have an account?
Louisa Pidcock 11
populate checkbox (after insert, after update) - please can anyone help me
Hi Guys
I am very very new to coding of any kind so please forgive me/ thank you in advance.
Custom Object: Buyer_Conact__c
I have a workflow rule that updates the due date if it falls on a weekend day. As 'Day__c' is derived via DATE() function in a formula thisrule only kicks in if the record it edited, which falls short of what is required.
I have added a checkbox called Weekend_Date_Handler__c which I would like to check after insert (as this will trigger the workflow)
I am attempting to refactor a piece of code I sucessfully created (you guys then helped me with the test class) for a different purpose and am not getting very far at all. My what I want is for the code to look at any buyer_contact__c records that have Weekend_Date_Handler__c= False and update them to Weekend_Date_Handler__c = True
Here is what I have written so far. Any guidance here is massively appreciated !
trigger weekendUpdate on Buyer_Contact__c (after insert, after update) {
List<Id> lstId = new List<Id>();
for(Buyer_Contact__c buyerConTwo: Trigger.new){
List<Buyer_Contact__c> buyerConTwoList = [SELECT Id,Weekend_Date_Handler__c, FROM Buyer_Contact__c WHERE Weekend_Date_Handler__c = FALSE] ;
buyerConTwo.Weekend_Date_Handler__c= TRUE
update buyerConTwoList;
}
}
I am very very new to coding of any kind so please forgive me/ thank you in advance.
Custom Object: Buyer_Conact__c
I have a workflow rule that updates the due date if it falls on a weekend day. As 'Day__c' is derived via DATE() function in a formula thisrule only kicks in if the record it edited, which falls short of what is required.
I have added a checkbox called Weekend_Date_Handler__c which I would like to check after insert (as this will trigger the workflow)
I am attempting to refactor a piece of code I sucessfully created (you guys then helped me with the test class) for a different purpose and am not getting very far at all. My what I want is for the code to look at any buyer_contact__c records that have Weekend_Date_Handler__c= False and update them to Weekend_Date_Handler__c = True
Here is what I have written so far. Any guidance here is massively appreciated !
trigger weekendUpdate on Buyer_Contact__c (after insert, after update) {
List<Id> lstId = new List<Id>();
for(Buyer_Contact__c buyerConTwo: Trigger.new){
List<Buyer_Contact__c> buyerConTwoList = [SELECT Id,Weekend_Date_Handler__c, FROM Buyer_Contact__c WHERE Weekend_Date_Handler__c = FALSE] ;
buyerConTwo.Weekend_Date_Handler__c= TRUE
update buyerConTwoList;
}
}
It is not a good idea to update the record in "After Update" trigger. Use "Before Update" and "Before Insert" for this operation. Also you do not have to write the update statement ("update buyerConTwoList; ") as the code will automatically either insert or update the records (based on which trigger is executing)
Your code should look like below:
Let me know if this helps.
**Please mark this as best answer if this answers your query.**
Thanks,
Manish Choudhari
14x Certified Salesforce Architect
Certification link: http://certification.salesforce.com/certification-detail-print?conId=003G000002gRrrEIAS
My Blog: http://sfdcfacts.com/
Youtube Channel: https://www.youtube.com/SFDCFacts
LinkedIn: https://www.linkedin.com/in/manish-choudhary/
Trailhead: https://trailhead.salesforce.com/en/me/manish-choudhari
Twitter: https://mobile.twitter.com/manish_sfdc
...if i populate the checkbox before insert then the WFR will not fire.. does this make sense? Essentialy i want to edit any newly created records so that they invoke the wfr that moves the date along ...
I have tested your suggested code (thanks again so much) and it is not doing what i need it to unfortunately becuase the wf only fires when the record is edited
You mean your workflow is not firing?
What entry criteria do you have? is it "created, and every time it’s edited"
It should always fire whether the record is created or edited. Can you please check debug logs to see if the workflow is fired or not?
I still dont understand how this would trigger the workflow rule if it is 'before insert' but that is probably because im a bit stupid!?
I will try to explain it better as I think my explanation might be a part of the problem....
1. Process A ) - Creates a Buyer Contact record with a Due Date = TODAY()+2
The Buyer contact record has a formula field 'Target Completion Day' which dervies the day from the due date.
2. Process B) - Looks at the Target Completion date and if it is a Saturday , add 2 days to the due date , if its Sunday it adds 1 day to the Due date
Unfortunately, process B is only triggered if the record is editied. To try to solve this I created a checkbox, default unchecked upon creation. I want the trigger to loook for these records and check the box (which is essentially just editing the record so that it enters process B)
Does this make any difference to what you have advised so far? So sorry if I am just being dumb here ...