0

Can we implement following functionality? if you have any inputs, please share.

Based on Parent Record Type (creation/update), need to create only one child record type record (on same object).

Ex: I have custom object with record types A (Master) and B (child) when A record created / updated with perticular values system needs to create only one B record

we have process builder (on create/update record criteria) - but it is creating multiple B records whenever user is updating A record, here i want to restrict to one record only.

UPDATE

Object Name – Intervention__c

Record Type(s) – on same object

Heppo Consult Intervention  Record Type 1  
Patient Intervention  Record Type 2 

Condition: If ‘Heppo Consult Intervention’ record type intervention is created / updated and following field values are met then create only one ‘Patient Intervention’ record type record (Intervention Record)

• Field1__c is not null ;

• Field2__c = ‘some value’ ;

  • A & B are two different custom objects OR A & B are Record Types in a same object ? – Jarvis Feb 3 '16 at 18:15
  • A and B are 2 record types on same object (custom object) & they no relationship in between. – Kiran Kulakarni Feb 3 '16 at 18:41
  • Kiran - I tried pasting in your comment but it needs more formatting – cropredy Feb 3 '16 at 23:27
  • can you screenshot or tell us what criteria you have put in your process builder, so we can idenitfy the issue. Also can you make sure there are no triggers running when "Heppo Consult Intervention" record type record is inserted/updated – sfdcFanBoy Jun 16 '16 at 8:45
1

You can create a new field on your parent object with roll up summary. It will contains number of child records count. once that is done you can put this as criteria in your process builder.

i.e. create records if Records counts==0

The basic objective is to find a condition which you can use to differentiate between update record and insert record.

  • Thank you so much for quick response Himanshu. But A and B are record types on same custom object & they are not Master-Detail related, so we cannot create roll-up field on Parent record (A) - please suggest. – Kiran Kulakarni Feb 3 '16 at 18:29
1

I am not proficient with the process builder but think insert is getting called twice. We can put a trigger on this object. This is a pseudo code, tweak it as per your metadata

    trigger insertRecordTypeB on Custom_object__c (after insert)
    {
       list<custom_object__c> blist = new list<custom_object__c>();
       // GET RecordType id for B
       Id Bid = RecordTypeCache.getRTid(Custom_object__c.sObjectType, 'B')

      for(custom_object__c obj: Trigger.new)
      { 
        if(obj.recordtypeid == RecordTypeCache.getRTid(custom_object__c.sObjectType, 'A'))
         {
            custom_object__c b = new custom_object__c(field1 = obj.field1, recordtypeid=Bid);
         }
           blist.add(b);
      }

       insert blist;
 }

Below is the code to retrieve the recordtypeid

public class RecordTypeCache
{ 
//Create a map of tokens for all the Record Types for the desired object
public static Map<String, Map<String,Schema.RecordTypeInfo>> rtsByObject = new Map<String, Map<String,Schema.RecordTypeInfo>>();

    public static string getRTId(sObjectType sObjType, string myRTName) {
        string objName = sObjType.getDescribe().getName();

      if (!rtsByObject.containsKey(objName)) {
              rtsByObject.put(objName, sObjType.getDescribe().getRecordTypeInfosByName());

      }

      Map<String,Schema.RecordTypeInfo> recordTypeInfo = rtsByObject.get(objName);

      if (!recordTypeInfo.containsKey(myRTName)) {
        throw new RTException('Record type "'+ myRTName +'" does not exist.');
      }

    //Retrieve the record type id by name
     return recordTypeInfo.get(myRTName).getRecordTypeId();

    }
        public class RTException extends Exception{}
    }
  • Hi Bennie, Thanks for the updates. Object Name – Intervention__c Record Type(s) – on same object • Heppo Consult Intervention  Record Type 1 • Patient Intervention  Record Type 2 Condition: If ‘Heppo Consult Intervention’ record type intervention is created / updated and following field values are met then create only one ‘Patient Intervention’ record type record (Intervention Record) • Field1__c is not null ; • Field2__c = ‘some value’ ; – Kiran Kulakarni Feb 3 '16 at 20:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.