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

Simple Trigger to Change Custom Object Record Type
Hi guys,
I have a custom object called User_Support__c in SFDC. I have an "Intake" record type that is the default for all users. Depending on there answer to a single field, i would like a trigger to change the record type. I have a formula field called "Record_Type_Conversion_Controller__c" that will determine the name of the record type i would like the record to be changed to.
I get the following error when I try it : ConvertRecordType: execution of AfterInsert caused by: System.QueryException: List has no rows for assignment to SObject Trigger.ConvertRecordType: line 8, column 1
Trigger ConvertRecordType on User_Support__c (after insert) {
User_Support__c u= Trigger.new[0];{
//hold current User Support Fields
u = [select Id, Record_Type_Conversion_Controller__c,Issue_Type__c, Name FROM User_Support__c WHERE Id=:u.id];
RecordType RecType = [Select Id From RecordType Where SobjectType = 'Opportunity' and DeveloperName=:u.Record_Type_Conversion_Controller__c];
If(u.Issue_Type__c =='License Request')
u.name='License Request';
If(u.Issue_Type__c !='License Request')
u.name='';
u.RecordTypeId=RecType.Id;
update u;
}
}
If anyone could help it woudl be greatly appreciated!!!!
I have a custom object called User_Support__c in SFDC. I have an "Intake" record type that is the default for all users. Depending on there answer to a single field, i would like a trigger to change the record type. I have a formula field called "Record_Type_Conversion_Controller__c" that will determine the name of the record type i would like the record to be changed to.
I get the following error when I try it : ConvertRecordType: execution of AfterInsert caused by: System.QueryException: List has no rows for assignment to SObject Trigger.ConvertRecordType: line 8, column 1
Trigger ConvertRecordType on User_Support__c (after insert) {
User_Support__c u= Trigger.new[0];{
//hold current User Support Fields
u = [select Id, Record_Type_Conversion_Controller__c,Issue_Type__c, Name FROM User_Support__c WHERE Id=:u.id];
RecordType RecType = [Select Id From RecordType Where SobjectType = 'Opportunity' and DeveloperName=:u.Record_Type_Conversion_Controller__c];
If(u.Issue_Type__c =='License Request')
u.name='License Request';
If(u.Issue_Type__c !='License Request')
u.name='';
u.RecordTypeId=RecType.Id;
update u;
}
}
If anyone could help it woudl be greatly appreciated!!!!
Please try to use below updated code. There may be some syntax errors. Let me know if you face any.
If this answer resolves the issue then please mark this answer as solution
All Answers
Please try to use below updated code. There may be some syntax errors. Let me know if you face any.
If this answer resolves the issue then please mark this answer as solution
Regards
here is the final code...