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 

guidance on trigger code

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
ObjectCh__c has a field(curreny_ --> amount__c)

Scenario:

when amount__c(on ObjectCh__c(childobject)) is blank or null, and if record type is either A||B and Picklst_a__c and picklist__b (on parent) is selected then Myamount__c should be required it cannot be blank
 
sachin sabusachin sabu
Hi,
You can simply use a validation rule on ObjectCh__c
AND(OR( ISPICKVAL( ObjectPar__r.Picklist_a__c , "") , ISPICKVAL( ObjectPar__r.Picklist_b__c , "")),ISBLANK( amount__c ),OR( ObjectPar__r.RecordType.Name ="A", ObjectPar__r.RecordType.Name ="B"),ISBLANK( ObjectPar__r.Myamount__c ))