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
apex code shareapex code share 

Please help me writing a trigger for cross checking of UIN's in different object.

Hi,

I have an custom object SALES RETURN:- in this i have a field EXTERNAL UIN.
Now when any input is given in this field.Firstly it should check whether this UIN already exist in the custom object UIN MASTER.
NOW, if it exists then it should check whether external UIN which is associated with 3 internal uin (i.e for mechanic,reborer and retailer) in another object say Coupon submission and therefore if the status field for any of the internal UIN is "submitted" then it should show an ERROR message 'INVALID UIN' .
-------------------------------------------------------------------------------------------------------------------------------------------------
just for understanding:
We have erternal UIN which are associated with internal UIN's (1 or 2 or can be 3)
Now we are just checking whether any external UIN or any of its associated internal uin is already submitted in the system.

Starz26Starz26

I have not ran through anonymous so it may require a bit of debugging

 

Trigger myTrigger on Sales_Return__c (before insert){

 

List<UIN_Master> lMaster;

MAP<UINTYPE,UIN_Master__c> mExistUIN = New Set<UINTYPE, UIN_Master__c>():

Set<UINTYPE> sNewUIN = New Set<UINTYPE>():

 

for(Sales_Return__c s : trigger.new)

   sNewUIN.add(s.External_UIN__c);

 

lMaster = [Select UIN__c From UIN_Master__c Where UIN__c IN :sNewUIN];

 

For (UIN_Master__c u : lMaster)

    mExistUIN.put(u.UIN, u);

 

 

for(Sales_Return__c s :trigger.new){

 

    if(mExistUIN.containsKey(s.UIN))

          s.addError('INVALID UIN');

 

 

 

}