You need to sign in to do that
Don't have an account?
NightShade
URGENT Help Needed :-Copy RecordTypeId into a field
Hi ,
I need to copy the RecordTypeId into a field called Prev_Record_Type which is a text field on opportunity. There are multiple record types on the Object and I need to get the selected recordtypId.Can someone please help me with the Trigger code since i am not all experienced in this and urgently need help .
Thanks and Regards
Not sure what the use case is, but before you code it, you can do that via workflow unless there is some complex logic there - just use a formula to update the text field
All Answers
use this for comparing the recordtypes:
RecordType accRecType=[Select Id From RecordType Where Name=:'RecordTypeName And SobjectType=:'Account' limit 1];
And inside your if loop you can compare the two recordtype ID for an opportunity.
for(Opportunity opp:Trigger.New)
{
if(opp.RecordTypeId=accRecType.Id)
{
}
}
Before you go down the Trigger path, consider if you can use Field History to accomplish this.
You can use Field History to track the changes of the Record Type.
Setup -> Customize -> Opportunity -> Fields - > Enable Field Tracking. Then select "Opportuinty Record Type".
I tried writing the trigger as follows and got the below error . Please advice .
Thanks
Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger RcdType caused an unexpected exception, contact your administrator: RcdType: execution of BeforeInsert caused by: System.QueryException: List has no rows for assignment to SObject: Trigger.RcdType: line 4, column 26
Not sure what the use case is, but before you code it, you can do that via workflow unless there is some complex logic there - just use a formula to update the text field
hi,
Use debug log to find error..
you get this error because your query result comes with no record [zero record];
plz check your record
Thank you all I resolved the problem by using a workflow which fires only when the record is created to copy the record type Id .