You need to sign in to do that
Don't have an account?
Cha Yang
Apex Trigger to update a field
I'm new to apex trigger so bear with me. I have Account and a custom object (InvsetigationContact). On the custom object I created a text field call CheckID that I want to use it for duplicate checking. I want to create the Before Trigger to filling in with combine of First+last Name + ContactID from the Account.
Not sure how to get started. Please help.
Not sure how to get started. Please help.
All Answers
You can get started from this trailhead unit: https://trailhead.salesforce.com/en/modules/apex_triggers/units/apex_triggers_intro
Your requirement looks quite straightforward, so it should not be difficult. Give it a shot and if you face any issues, post the code here, so we can help.
Thanks.
If the name of the lookup to Account is Account__c then your formula would be Assuming that first, lastname and contactid are the API names of those fields on the Account object.
You can use this formula syntax in Process Builder to create a process that updates that field as required.
ClassTestDupcheckID
Method Nameinsertic
Pass/FailFail
Error MessageSystem.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, DupCheckID: execution of BeforeInsert
caused by: System.NullPointerException: Attempt to de-reference a null object
Trigger.DupCheckID: line 9, column 1: []
Stack TraceClass.TestDupcheckID.insertic: line 8, column 1
Then your test must inspect the DupCheckID__c field to ensure that it was properly populated.
Something like this is what is required.