function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
BegginerBegginer 

quick help on tigger

Hi all, 

I'm learning triggers in salesforce and want some advice on understanding how to write a trigger for below scenario. what is the approach?

There are two objects ObjectPar__c(Parent) and ObjectCh__c(child) having look-up relationship.

Summary:
ObjectPar__c has record types namely  "A" and "B".
ObjectPar__c has a field (currency) --> Myamount__c
ObjectPar__c has 2 picklislts --> Picklist_a__c and Pciklist_b__c( two values "checked" , "Received")
ObjectCh__c has a field(curreny_ --> amount__c)

Scenario:

if record type is either A||B and Picklst_a__c and picklist__b ("checked") (on parent) is selected and Myamount__c is not entered and record is saved, then user from the related list selects the child object and on the child object if amount__c(on ObjectCh__c(child object)) is blank or null, and saves the record and when user come to parent object and changes the Pciklist_b__c("Received ") then the trigger should fire.
JeffreyStevensJeffreyStevens
Your Scenario got a little confusing, but I'll take a stab at it.

I think you want an AFTER UPDATE trigger n the ObjectPar__c object.  So that means that the trigger will fire every time the ObjectPar__c record is updated.  I think your trigger code should then take the ObjectPar__c IDs that fired the trigger - go and get all of the ObjectCH__c records for each ObjectPar__c record that fired the trigger. (Remember - a trigger can be called with upto 200 records at a time - so your code needs to be able to handle that.  It's called Bulkification of your code).  Then you can loop through each of the child records for each parent and make a decision on what needs to be done.

Here's where I didn't follow your scenario very well.  Not sure if you want something updated on the parent record or not.  If you're updating something on the parent record - then the trigger might need to be a BEFORE UPDATE trigger on the parent - NOT an After Update.
BegginerBegginer

What if the scenario is like below, how should i approach??

There are two objects ObjectPar__c(Parent) and ObjectCh__c(child) having look-up relationship.

Summary:
ObjectPar__c has record types namely  "A" and "B".
ObjectPar__c has 2 picklislts --> Picklist_a__c and Pciklist_b__c
ObjectCh__c 

Scenario:

if record type is either A||B and Picklst_a__c and picklist__b ("checked") (on the parent) is selected and there are records on the child object then trigger should fire on the parent object.
if there are no records on child object then trigger should not fire.