Let's say I have a Contact, we'll say from Trigger.new. If I want to update its parent account, I skip a query by initializing it in memory like this.
Account acct = new Account(Id = contactInstance.AccountId);
update acct;
Now I'm trying to apply the same idea, but with dynamic apex using the new Type class. My object name comes from a custom setting. And because in this instance I'm working with Attachment, and ParentId in this instance, and ParentId can be one of many different types, I'm really trying to avoid the DB trip for a second query. Only, it doesn't work:
Type t = Type.fromName(setting.ObjType__c);
sObject myObjInstance = t.newInstance();
myObjInstance.put('Id',attachmt.ParentId);
etc...
An sObject Id will allow initialization, but it is not writable.
Anyone know any workarounds on this one? Or is it wait for API version 27?