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
Pranav S SanvatsarkarPranav S Sanvatsarkar 

Clone method working i on one instance and not working on other instance

Hello there,

I have encountered a strange issue which is not allowing to complete my study about sObject clone method. Following is my code which is working fine on one of my instance and giving system limit exception of Heap size while executing. Please, note that I am executing this code in Anonymous window
 
List<Attachment> lstAttachments = new List<Attachment>();
Attachment clonedAttachment;
for( Attachment attachment : [SELECT  SystemModstamp, ParentId, OwnerId, Name, 
            LastModifiedDate, LastModifiedById, IsPrivate, IsDeleted, 
            Id, Description, CreatedDate, CreatedById, 
            ContentType, BodyLength, Body FROM Attachment WHERE ParentId = '003A000001zbugAIAQ' LIMIT 1] )
{
	clonedAttachment = attachment.clone(false,false);
	clonedAttachment.ParentId = '006A000000ZGmbd';
    lstAttachments.add(clonedAttachment);
}
insert lstAttachments;

Thanks in advance.
Wilfredo Morillo 20Wilfredo Morillo 20
Check the IDs. Do a select on contacts and opportunity to check if that's the record you intended to use. 
SELECT id, Name FROM Contact Where id = '003A000001zbugAIAQ';

SELECT id,Name FROM Opportunity Where id = '006A000000ZGmbd';

Also would be helpful if you show the error you are getting.

wil,  
 
Arp_SFDCArp_SFDC
Hi Pranav,

you are getting heap size error because of attachment that you want to clone

Please try to clone the attachment of less size, so total size of both attachment(Original and clone) not cross the heap size limit.


Thanks
Arpit