function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
AlecSAlecS 

RecordType field exists, still system says it does not

I am trying to assign the Record Type of Opportunity to the Record Type of Contract being created.

 

Within the Opportunity object, there's a standard field called RecordType. However, when I assign this value

 

con.RecordType = opp.RecordType;

 

I get this error message:

 

Error: Compile Error: No such column 'RecordType' on entity 'Opportunity'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names. at line 4 column 22

 

How can I resolve this?

 

Thank you!

Best Answer chosen by Admin (Salesforce Developers) 
Naidu PothiniNaidu Pothini
con.RecordTypeId = [SELECT Id, SobjectType, Name FROM RecordType WHERE Name = :opp.RecordType.Name AND SobjectType = 'Contact'].Id;

 try this.

All Answers

Naidu PothiniNaidu Pothini
con.RecordTypeId = [SELECT Id, SobjectType, Name FROM RecordType WHERE Name = :opp.RecordType.Name AND SobjectType = 'Contact'].Id;

 try this.

This was selected as the best answer
AlecSAlecS

I have tried that and this is the error message I get:

 

Error: Invalid Data. 
Review all error messages below to correct your data.
Apex trigger createContract caused an unexpected exception, contact your administrator: createContract: execution of AfterUpdate caused by: System.DmlException: Insert failed. First exception on row 0; first error: INVALID_CROSS_REFERENCE_KEY, Record Type ID: id value not valid for the users profile: 01250000000DnZkAAK: [RecordTypeId]: Trigger.createContract: line 198, column 1

 

Naidu PothiniNaidu Pothini

I have updated the post try it.

AlecSAlecS

Thanks, that works, Naidu!