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
YashhYashh 

formula field to chnage record type

So i have some requirement  that in the product object  there is one field Record Type(Abc) so if i change to another record type(Xyz) type.in the  product there is product offering  object so there will be fetch your checkbox will active_c(true)
And in prduct offering there is one formula field status_c Approved

So what is my Condition  that
if record type is changed  .make status is approve and checkbox will active
 it will work on new created also.
Suraj Tripathi 47Suraj Tripathi 47
Hi,
So you have two object product and product offering and you if record type of product object change then product offer fields that are status__c and active_c should change to Approved and True respectively?

Can you please tell if Product_Offer is the child of the product object?

Thanks & Regards
Suraj Tripathi
Suraj Tripathi 47Suraj Tripathi 47
Hi,
Please take the reference from below code and change the field name according to your requirement:-
trigger ProductTrigger on Product2 (after insert, after update) {
   if(trigger.isafter &&(trigger.isUpdate || trigger.isinsert))
   {
       for(product2 p:trigger.new ){
       if(p.recordType!= Trigger.oldMap.get(p.ID).recordType )
       {
           productOfferHelper.disp(trigger.new);
       } 
   }
}
}

///////////////////////////////////////////////////////////////////////////////////

public class productOfferHelper {
    public static void disp(List<product2> proList){
        List<Product_Offer__c> pList = [select id, Product__c, status__c, active__c from Product_Offer__c where Product__c in: proList];
     
        for(Product_Offer__c p:pList){
           p.status__c = 'Approved';
            p.active__c = True;
        }
        update pList;
    }
}


Please mark it as Best Answer if it helps you.

Thanks & Regards
Suraj Tripathi
Parish Haldkar 11Parish Haldkar 11
Hi Yash,

I understand your requirement. The best way would be to use the process builder on the object 'Product'. And then when the 'Record Type' field is edited/created in the 'Product' record, then you can update the 'Status__c' and 'Active1__c' field on your 'Product_Offer' child object.

If it helps, please mark it as the best answer to help others