You need to sign in to do that
Don't have an account?
hector.asp2
RecordType only saves Account
Hi ,
I have a custom object in which I save the record type (it can be accounts, contacts, leads).
Here is my code
String obj='Contacts'; RecordType rt = [select id, name from recordtype where name =: obj limit 1]; System.Debug(rt.name); //Gives Contacts savedGrp.RecordType = rt; insert savedGrp; it always saves accounts...
Please help me with this.
Thanks
Hector.
What happens if you try changing this line:
to this:
I don't see why the latter should work and the former shouldn't, but the latter is how I set Record Types on objects.
I think a problem is occuring when you get/set the record type and so the default record type is applied (is Accounts the standard record type for the profile & object).
All Answers
Can you post the rest of your code - e.g. what is savedGrp declared as?
If you want to get recordtype for specific object like account,object then in this case you should add sobjecttype = 'contact' in SOQL Query :
RecordType rtype = [Select r.SobjectType, r.Name, r.Id From RecordType r where name='individual' and SobjectType='contact']
Hope this helps.
Hi,
I tried to fire different queries and see what type of record types do I have
Then I did this
Then I tried
Please guide
Thanks.
Hector
What do you mean by "it always stores accounts"? Have you checked the objects in the database and found that the id doesn't match the id you specified when you created the record? Or are you experiencing problems elsewhere that lead you to this conclusion?
Hi,
Yes , I did checked the IDs and found that all for all cases only accounts id (the Master record type is Account ), is getting saved in recordtypeid for my custom object, though system.debug prints correct id before I do the insert.
Regards
Bikram...
What happens if you try changing this line:
to this:
I don't see why the latter should work and the former shouldn't, but the latter is how I set Record Types on objects.
I think a problem is occuring when you get/set the record type and so the default record type is applied (is Accounts the standard record type for the profile & object).
Does the profile running the code have access to the different record types? If not, it may be that account is the default and you are picking that up.