You need to sign in to do that
Don't have an account?
Selina Suarez
how to change a record type name in my apex class
I have a lead conversion process and I want to change the name of one of my record types. When I change it from my record type list- it causes the apex class to return errors. How do I change the record type name within my apex class coding. I used the search magnifying glass icon to look up instances of the old name in the apex class and replaced with the new name but this does not seem to be working.
Can anyone offer any advice here. i am at the beginning stages of learning to code with APEX.
Thanks!
Can anyone offer any advice here. i am at the beginning stages of learning to code with APEX.
Thanks!
All Answers
I believe there are workflow rules and other things associated with the conversion process.
Bori, Do you mean- add this piece of code to the beginning of the Apex class?
You can add the method "getRecordTypes" anywhere in your code, but where you're hardcoding the ID in your code, replace that line with "lead.RecordTypeId = recordTypes.get('Lead').get('YOUR_RECORD_TYPE_DEVELOPER_NAME');". You should be always getting the record type ID based on the record type Developer Name which you can find in setup -> customize -> leads -> record types -> your preferred record type.
if (!usingExistingNominee) {
// Look for an existing application lead and use that on the nomination instead of this one we're converting
try {
Lead existingApplicationLead = [
SELECT Id FROM Lead WHERE Email = :lead.Email AND RecordTypeId = :GlobalVariables.applicantTypeId
and IsConverted = false];
nomination.Nominee_Lead__c = existingApplicationLead.Id;
}
Apex Test Failures
Class Name: MassConvertLead
Method Name: MassConvertLead testMassConvertLead System.QueryException:
Error Message: List has no rows for assignment to SObject
Stack Trace: Class.MassConvertLead.testMassConvertLead: line 55, column 1
I recently changed the record type name and line 55 is pointing to something referencing the record type name as follows:
Id recordTypeId = [Select Id From RecordType Where SObjectType = 'Lead' And Name = 'National Admissions Application'].Id;
National Admissions Application is the new record type name.