0

I am very new to writing triggers hence would like some direction on how to write one, apologies.

Scenario: I have Custom Object (Location__c) which contains custom fields postcode (LL_Postcode_c) and (LL_Location_Number__c).

When both values in a Location object record match the values of fields in Account object (A_Postcode__c) and (A_Location_Number__c), respectively I would like the Account lookup field (named A_Location__c) to populate with the name of Location record where the two fields matched.

Can you please point me to the right direction as to how to proceed with this?

Many thanks for your help!

  • 1
    Welcome to SFSE. Please review the How to ask. There some good trailhead modules to get you started on writing triggers and also testing them. Once you have made an attempt, update your question with an example of the code you are having difficulty with and the community will be sure to help you out. – TSmith Oct 2 '18 at 10:16
0

Welcome to salesforce triggers :)

Rather than giving you the code, I will suggest you go through the following links:

  1. https://trailhead.salesforce.com/en/modules/apex_triggers
  2. https://github.com/kevinohara80/sfdc-trigger-framework

To follow up on that information, Firstly what you need to identify is which object the trigger should be on. In this case, the trigger would be on the Location__c object.

Secondly, you need to identify when do you want your logic to be fired. It may be beforeInsert, beforeUpdate, etc. I will also suggest that you specify the logic for specific field changes that you are looking for. In this case it will be the change of values of fields, Postcode__C and Location_Number__c.

Lastly, you will need to query, fetch and assign the records.

To throw in a curve ball, you will need to bulkify the trigger. I will let you figure that one out by going through the links above.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.