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);)

  • 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 Jul 5 '17 at 18:27
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

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.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.