+ Start a Discussion
DixitDixit 

RecordType.Name on Trigger

I have a Trigger on Opportunity which is working fine except for 1 field.... 
 
for(Opportunity run: Trigger.new){

 Opportunity old = Trigger.oldMap.get(run.Id);
        if (trigger.isupdate && run.invitar_al_centro_de_experiencia__c == true && old.invitar_al_centro_de_experiencia__c == true )
        {

 invitacion_al_centro_de_experiencia__c cand = new invitacion_al_centro_de_experiencia__c();
                cand = [SELECT id, name FROM invitacion_al_centro_de_experiencia__c WHERE oportunidad_relacionada__c =: run.id LIMIT 1];

 cand.Tipo_de_Oportunidad__c = string.valueof(run.recordtype.name);

}

}

The "run.recordtype.name" returns null
but if i change that line to "run.recordtypeid" it shows me the recordtype ID indeed. 
I tried with and without the "string.valueof()" and still getting "null"...and checked out the recordtype and it does have a name....
(I cut the code, so sorry if there is not a "{", "}", or anything written) 

What am i doing wrong?
Best Answer chosen by Dixit
RainnyCloudyRainnyCloudy
You're getting null, because you only get the values of the current sObject for your trigger, which for you is Opportunuity. RecordType is a seperate related object, so you do have access to the recordtypeId but not the name. If you need the record type name you could get it using the schema class to get it. 

All Answers

RainnyCloudyRainnyCloudy
You're getting null, because you only get the values of the current sObject for your trigger, which for you is Opportunuity. RecordType is a seperate related object, so you do have access to the recordtypeId but not the name. If you need the record type name you could get it using the schema class to get it. 
This was selected as the best answer
RainnyCloudyRainnyCloudy
Here's a link that asked a simular question and shows examples:

http://salesforce.stackexchange.com/questions/13567/why-am-i-not-getting-the-record-type-name-when-i-use-recordtype-name
DixitDixit
@Luke 

Thank you, i read about that method but i thought it was not used in my case... I thought "RecordType" was like any other find field which you can access with the "__r.name" 
Thanks a lot.