+ Start a Discussion
Neha RNeha R 

Assign master record type using apex

I want to assign Master record type to new opportunties using Apex code, we do have one custom record type as well but we want the master record type to be assigned to new opportunities that are systematically created using Apex code.
I have tried assigning null, using recordtypeinfos methods with schema describe and hardcoding 012000000000000AAA just to debug but i keep getting this error-
Record Type ID: this ID value isn't valid for the user: 012000000000000AAA;getStatusCode=INVALID_CROSS_REFERENCE_KEY;
Is there a way to assign out of box master record type to new opportunites using Apex or do i have to create another custom Master record type?
CloudGeekCloudGeek
Hello Neha,

Instead, try to assign like :

Opportunity opp = new Opportunity();

opp.RecordType.Name = 'Your Record Type Name' ;

and try.
CloudGeekCloudGeek
Forgot to include this note :
Record Type ID: this ID value isn't valid for the user: 012000000000000AAA;getStatusCode=INVALID_CROSS_REFERENCE_KEY;

That error seems like , you might have missed assigning the record type for Profile in your context ?

Go to the USer's Profile--> Record Type Settings   here you can check the assignment for record type.
Neha RNeha R
Hi Venkat, 
Thanks for your reply, however i do have access to the master record type, i am doing a isavailable() check on the recordtype info and then assigning the recordtype to the new opportunity record, however on insert it fails giving me the error.
Also it gives a null pointer exception on using the recordtype name as recommended in your first post, i believe we should only use recordtypeid for rt assignment and not name.

Is there any apex documentation which says we cannot assign master record type once a custom record type has been created for an object? if there is then isavailable function is deceptive.
This link talks about master rt not being available in configuration but not in custom code -
http://help.salesforce.com/apex/HTViewSolution?id=000005125&language=en_US