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
Saravanan @CreationSaravanan @Creation 

Creating newsobject based on record id

Hi All,

I want to create sobject instance record id. If any on know please help me

for(sobject rcd: sobjectRecordList)
{
             sObject obj = Schema.getGlobalDescribe().get(rcd.id).newsObject();
}

sobjectRecordList is a collection of recods with different type.

Thanks,
ShashForceShashForce
Hi Saravanan,

It is not very clear what you are trying to do here. Can you please explain so that I can suggest something?

Thanks,
Shashank
Saravanan @CreationSaravanan @Creation
Hi,

I want to create an sobject instance based on record id. In my below code I am running with the for lop
list of record with different type.

Assume 'sobjectRecordList' contains records of 'Account', 'Contact', 'Cases' etc.Now I want to create
intace base on type of records inside the for loop.

list<sobject> sobjectRecordList=new list<sobject>();

for(sobject rcd: sobjectRecordList)
{
             sObject obj = Schema.getGlobalDescribe().get(rcd.id).newsObject();
}

Hope my explanation is clear to you.
MagulanDuraipandianMagulanDuraipandian
http://www.infallibletechie.com/2013/05/how-to-find-object-type-from-salesforce.html

Check this

If this solves your problem, kindly mark it as the best answer.
Hit Like, if it saved your work :-)

Regards,
Magulan
http://www.infallibletechie.com
ShashForceShashForce
Hi,

Please try something like this:

for(sobject rcd: sobjectRecordList)
{
             sObject obj = rcd.getSObjectType().newSObject(rcd);
}

If this answers your question, please mark this as the Best Answer for this post, so that others can benefit from this post.

Thanks,
Shashank