0

class...

public class ExceptionCreateExceptionRecord{
public static void insertException(Map<string, string> param)
    {    
    Exception__c newExcept              =   new Exception__c();
        newExcept.ExceptionTypeCode__c      =   param.get('ExceptionTypeCode__c');
        newExcept.RecordType.DeveloperName  =   'New Exception'; 


test class

    @isTest(SeeAllData=true)
    public class TestExceptionCreateExceptionRecord {
       static testmethod void Exception(){
        map<String ,String> parm=new map<String,String>();
            parm.put('ExceptionTypeCode__c', 'open');                
            parm.put('entry2','Second entry'); 
       ExceptionCreateExceptionRecord excep=new ExceptionCreateExceptionRecord();   
        ExceptionCreateExceptionRecord.insertException(Parm);

stacktrace

Class.ExceptionCreateExceptionRecord.insertException: line 7, column 1( newExcept.RecordType.DeveloperName = 'New Exception'; ) Class.TestExceptionCreateExceptionRecord.Exception: line 8, column 1( ExceptionCreateExceptionRecord.insertException(Parm);)

1
  • Is this still an open question? You mentioned in some of the questions that your problem was solved but never accepted an answer...
    – Adrian Larson
    Commented Jul 5, 2017 at 18:27

2 Answers 2

1

Not entirely clear from the other answers/comments that this is solved yet. The key point is that to set a record type you must relate the object to an already existing RecordType object by setting that already existing RecordType object's ID in the RecordTypeId field:

List<RecordType> rts = [
        SELECT Id FROM RecordType
        WHERE SobjectType = 'Exception__c'
        AND DeveloperName = 'New_Exception'
        ];
newExcept.RecordTypeId = rts[0].Id;
0
0

In this example you are trying to access RecordType's attribute DeveloperName before even its declared.

newExcept.RecordType.DeveloperName = 'New Exception';

  • First set the RecordType for the newExcept, then try setting the DeveloperName

  • I am not sure why you are using RecordType.DeveloperName to set the Exception Name. It would be better to add a field in Exception__c called DeveloperName.

2
  • List<RecordType> lstRecordType = [SELECT id FROM RecordType WHERE SobjectType = 'Exception__c' AND DeveloperName = 'New_Exception']; newExcept.RecordType.DeveloperName = 'New Exception'; Commented Feb 15, 2016 at 7:26
  • i set the record type Commented Feb 15, 2016 at 7:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .