Note that listAttachment and listMigrationObject is the biggest contributor on this exception.
Below I share snippet on how I retrieve listAttachment that causing exceed ViewState.
listAttachment = [Select Name,Id,ParentId,Parent.Type,Owner.Name,Owner.Id ,Owner.IsActive ,ContentType,isPrivate from Attachment where Parent.Type =:selectedParent ]; Map<Id,Attachment> mapAttachment = new Map<Id,Attachment>(); for(Attachment att : listAttachment){ mapAttachment.put(att.Id,att); }
I change the code to below :
for(Attachment att : [Select Name,Id,ParentId,Parent.Type,Owner.Name,Owner.Id ,Owner.IsActive ,ContentType,isPrivate from Attachment where Parent.Type =:selectedParent ]){ mapAttachment.put(att.Id,att); }
Note that assigning SOQL to list and directly use SOQL in the loop will make a different.
See, there is no longer exception. I will do the same on the other list.
You might want to check on An Introduction to Visualforce View State .
Have a great weekend.
No comments:
Post a Comment