You need to sign in to do that
Don't have an account?

Need help truncating an ID properly
I'm working with this at the moment:
List<RecordType> id = [select ID from RecordType where Name = 'Quote']; if (id.isEmpty()){ ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'No ID found.')); return null; } rectypeid = String.valueOf(id[0].ID);
cncl = new Cancelations__c();
cncl.Id = rectypeid;
cncl.Date__c = cDate;
cncl.Contract_Holder__c = name;
cncl.Customer_Pay__c = custPrice;
cncl.Cancelation_Fee__c = cFee;
cncl.Cx_Method__c = method;
cncl.Deduction__c = deduction;
I'm trying to get it to return the proper ID value, but it keeps returning the 18 digit version instead of the 15 digit one so when I try and pass it back to salesforce it says it's an invalid ID for the object and I can't figure out either ther best way to truncate it or pass it back so it will accept it. I've tried typcasting it as an ID, various string methods to remove the extra characters, but without success, and it's wearing a little thin so any advice on perhaps a better way to do it, or a correction if I'm doing it completly wrong would be great.
Hi Carter ,
There might be a possiblity that that a recordType by the name 'Quote' can be present for another object as well. in the SOQL query can you add another condition like this:
Also, you can assign the recordType directly.
-ಸಮಿರ್
All Answers
I don't think the problem has anything to do with truncation of the Id.
The cancelation object is not a RecordType therefore you are assigning an incorrect Id to the object. Shouldn't you be assigning the RecordTypeId field not the Id field?
Ram
I had tried that, but for some reason when I make the attempt with the RecordTypeId field I get an error when trying to insert stating that I'm attempting to de-reference a null object, but given that I know I have a value that was confusing me as well.
Hi Carter ,
There might be a possiblity that that a recordType by the name 'Quote' can be present for another object as well. in the SOQL query can you add another condition like this:
Also, you can assign the recordType directly.
-ಸಮಿರ್
The suggested adjustments worked, and sfdcfox was correct, the insert was caused by an error elsewhere.