+ Start a Discussion
AnonymouseAnonymouse 

How to Use Process Builder to Use Custom Event Field to Have Record Type of a Related Opportunity

Hello,

How may I use Process Builder to use a custom Event Field to have the "Record Type" of a related Opportunity? What kind of field(s) do I need to create? For instance, do I create any Lookup fields? If so, are they custom Activity Fields? If this is the case, what are these fields related to? Or, are they formula fields? How may I go about doing this? Any help would be greatly appreciated.

Sincerely,
Jackie
Best Answer chosen by Anonymouse
Narender Singh(Nads)Narender Singh(Nads)
Hi Jaquelyne,
What you want to achieve is not possible via process builder or workflow or custom formula field.
You will have to write a trigger in order to achieve that.

Your trigger will look something like:
trigger UpdateRecTypeID on Event (after insert) {
    
    list<id> OppIds=new list<id>();
    list<id> eIds=new list<id>();
    event[] Elist=new event[]{};
    for(event e:trigger.new){
        string OppID=e.WhatId;
        if(OppID.startsWith('006')){
            eIds.add(e.id);
            OppIds.add(e.WhatId);
        }
    }
    
    Elist=[select id,whatid,Record_Type_ID__c from event where id in :eIds];
    map<id,opportunity> accmap=new map<id,opportunity>([select recordtypeid from opportunity where id in :OppIds]);
    
    event[] UpdateList=new event[]{};
    for(event e: elist){
        e.Record_Type_ID__c=accmap.get(e.whatid).recordtypeid;
        UpdateList.add(e);
    }
    
    update UpdateList;

}

Note:
Record_Type_ID__c is a custom field of type text.
This trigger will work on event but not on task.
For Task object you will have to write a similar trigger.

Let me know if it helps.
Thanks

All Answers

Prashant Pandey07Prashant Pandey07
Process builder may not work in this case..related to is not specific to one object and your process builder may not dynamically which object is selected.

You can use apex to populate the event custom field.


--
Thanks,
Prashant
 
AnonymouseAnonymouse
Hi Prashant,

Thank you for your reply. Which logic steps may I follow to do this in Apex?

Sincerely,
Jackie
Prashant Pandey07Prashant Pandey07
Hi Jaquelyne,

I found somewhat similar request you may check here..and let me know if it works, other wise will send you apex code..

https://success.salesforce.com/answers?id=9063A000000iQPmQAM

--
Thanks,
Prashant
Narender Singh(Nads)Narender Singh(Nads)
Hi Jaquelyne,
What you want to achieve is not possible via process builder or workflow or custom formula field.
You will have to write a trigger in order to achieve that.

Your trigger will look something like:
trigger UpdateRecTypeID on Event (after insert) {
    
    list<id> OppIds=new list<id>();
    list<id> eIds=new list<id>();
    event[] Elist=new event[]{};
    for(event e:trigger.new){
        string OppID=e.WhatId;
        if(OppID.startsWith('006')){
            eIds.add(e.id);
            OppIds.add(e.WhatId);
        }
    }
    
    Elist=[select id,whatid,Record_Type_ID__c from event where id in :eIds];
    map<id,opportunity> accmap=new map<id,opportunity>([select recordtypeid from opportunity where id in :OppIds]);
    
    event[] UpdateList=new event[]{};
    for(event e: elist){
        e.Record_Type_ID__c=accmap.get(e.whatid).recordtypeid;
        UpdateList.add(e);
    }
    
    update UpdateList;

}

Note:
Record_Type_ID__c is a custom field of type text.
This trigger will work on event but not on task.
For Task object you will have to write a similar trigger.

Let me know if it helps.
Thanks
This was selected as the best answer
Narender Singh(Nads)Narender Singh(Nads)
Mark it as the best answer if it helps you.
Thanks.
AnonymouseAnonymouse
Thank you Prashant and Narender.