You need to sign in to do that
Don't have an account?
Jose María Nicolás Arfelis
Invoking Account Record Type fields in APEX
Hi all,
I would like to create a Trigger Handler invoking an Account record type, but after some research and test I couldn't find the way to invoke a specific record type and fields of that record type in APEX. The name of the Account record type I am talking about is "Profesores". Here is my code:
Can please somebody help me as I am stuck here since hours?.
Regards
I would like to create a Trigger Handler invoking an Account record type, but after some research and test I couldn't find the way to invoke a specific record type and fields of that record type in APEX. The name of the Account record type I am talking about is "Profesores". Here is my code:
public with sharing class ProfesorEventoTriggerHandler { @future public static void ProcesaProfesoresAsync(Set<ID> eventoIds){ // recoge el map del evento id y de los profesores sepprevados por punto y coma a construir Map<Id, String> eventoProfesorMap = new Map<Id, String>(); //RecordType RecType = [Select Id From RecordType Where SobjectType = 'Account' and DeveloperName = 'Profesores']; // consigue TODOS los profesores para todos los eventos afectados de tal modo que podamos construir List<Relacion_Profesor_Evento__c> eventoProfesores = [select id, Evento__c, RecType.Id Account.Name from Relacion_Profesor_Evento__c where Evento__c IN :eventoIds order by Account.Name]; for (Relacion_Profesor_Evento__c prev : eventoProfesores) { if (!eventoProfesorMap.containsKey(prev.Evento__c)) { // si el key del evento no existe, agregarlo con nombre del profesor eventoProfesorMap.put(prev.Evento__c,prev.Account.Name); } else { // si el key del evento ya existe, agregar ", // if the key (account) already exist, add "; nombre del profesor" eventoProfesorMap.put(prev.Evento__c,eventoProfesorMap.get(prev.Evento__c) + ', ' + prev.Account.Name); } } // consigue los eventos que fueron afectados List<Evento__c> eventos = [select id from Evento__c where Id IN :eventoIds]; // agrega la lista de profesores separados por punto y coma for (Evento__c ev : eventos) ev.Account = eventoProfesorMap.get(ev.id); // actualiza los eventos update eventos; } }Account.Name should be for example something like this "get the value in field Name of the Record type "Profesores" of the object Account".
Can please somebody help me as I am stuck here since hours?.
Regards
I'm not clear how you want to use the record type of Account in this logic. More explanation in your question would help.
Taking a guess, if Relacion_Profesor_Evento__c is a child object of Account and you only wanted records related to the 'Professors' Account record type you could filter like this:
Please mark this post as solved if it helps.
Best Regards,
Nagendra.P
in the code you can see Account.Name is mentioned more than one time, but that is not what I exactly mean. The object Account in my application has two record types: one is the Record Type "Profesores" and the another is "Alumnos".
The parent object is Evento. The child object is a related list based on a junction object between the Evento object and the Account Record Type = Profesores (I have two lookups in this junction object, one of them points to Account with a filter for RT "Profesores").
So, what I am trying to do is to build a concatenated string of ";" separated values in a text field. The text field will contain the Names of the "Profesores" separated by a ";".
Say, I have my Event X and the related list for that event with the Professors participating on that event:
PROFESOR FECHA DE CREACION
***********************************************
Julian Perez 18/9/2016
Maria Velasquez 18/9/2016
my concatenated string appearing on the detail page of the Event X on the corresponding field would be:
Julian Perez;Maria Velasquez
As PROFESOR comes from the lookup Account, Filter with RT = "Profesores", I would like to invoke that RT in my code. If I invoke Account.Name, Salesforce doesn't know which RT I am talking about, if Profesores or Alumnos. I guess, I can not save my code because of this.
I can not find out how to invoke this RT.