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
Sourav PSourav P 

salesforce how to update a field as per a related object field value

Hi,
I have a custom object " Transaction ( API Name : Quotation__c) " and a related object " Biz Validation" on it.
User-added image

I want that, if there is any records exists in the " Biz validation" related object , the field " Biz Validation exists" value in the " Transaction" object should be "YES". can anyone plz suggest how to achieve this. I have the look up relationship between the two objects ( Biz valid being the child object). I have written the below trigger for it, although its not showing any errors while saviing, also its not working. Can anyone plz pont out where i gone wrong in the below trigger? Thanx
 
trigger updateTrans on Biz_validations__c (after update) {
Map<Id, Biz_validations__c> bizValidWithAuthLimit=new Map<Id, Biz_validations__c> ();
for(Integer i=0; i<Trigger.new.size();i++){
if(Trigger.new[i].Authority_limit__c != null) 
{
bizValidWithAuthLimit.put(Trigger.new[i].id,null);
}
}
                                                     
List<Quotation__c> updatedTrans=new List<Quotation__c>();

    for (Quotation__c q : [SELECT id,Biz_Validation_Exists__c FROM Quotation__c WHERE id
                            in :bizValidWithAuthLimit.keySet()])
                      
                          {
  Biz_validations__c parentBizValid = bizValidWithAuthLimit.get(q.id);
  q.Biz_Validation_Exists__c= parentBizValid.Authority_limit__c;
  
  updatedTrans.add(q);
  
  }
update updatedTrans ;                   
}

 
Best Answer chosen by Sourav P
Dilip_VDilip_V
Sourav,

Biz_validation object is related to which object?

Lets say if Biz_Validation is related to X obj.

I will write a workflow rule/Process builder on X obj to update the 'Biz Validation exists' field on Biz_validation.
Lets say look up field from X to Biz_validation is Biz_V__C
Steps for process builder:
1.Create workflow rule on X(When a record is created/edited).
2.Condition:Null check on look up field i.e Biz_V__C.
3.Action:Update records-Update the 'Biz Validation exists' on Biz_Validation.

Let us know if you have any issues.

Mark it as best answer if it works.

THanks.

 

All Answers

Dilip_VDilip_V
Sourav,

Biz_validation object is related to which object?

Lets say if Biz_Validation is related to X obj.

I will write a workflow rule/Process builder on X obj to update the 'Biz Validation exists' field on Biz_validation.
Lets say look up field from X to Biz_validation is Biz_V__C
Steps for process builder:
1.Create workflow rule on X(When a record is created/edited).
2.Condition:Null check on look up field i.e Biz_V__C.
3.Action:Update records-Update the 'Biz Validation exists' on Biz_Validation.

Let us know if you have any issues.

Mark it as best answer if it works.

THanks.

 
This was selected as the best answer
Sourav PSourav P
Hello, Thanks a lot. I used the process builder now. and it worked. Actually , you have written opposite, " Biz validation exists" field in teh Quotation object , which need to get updated. and the related object in the "Quotation" object is the " Biz validation" object. But its OK, i got the concept , i just took the opposite objects what you suggested , and it worked in Process builder. I was trying trigger initially. Thanks