Saving and restoring states in dx12 command context

Hi, all
I am writing my own render passing function in the FD3D12ComandContext::RHIRender
A situation makes me to create separate DescriptorHeap so I called

cmdList->SetDescriptorHeaps(1, &MyDescHeap);
MyRender();
// Here I should restore the original DescriptorHeap and other state

First, I tried to save current descriptor heap like below

ID3D12DescriptorHeap* CurrentSRVHeap = StateCache.GetDescriptorCache()->GetViewDescriptorHeap();

    cmdList->SetDescriptorHeaps(1, &MyDescHeap);
    MyRender();
    cmdList->SetDescriptorHeaps(1, &CurrentSRVHeap); 

But if fails with d3d debug layer output below

D3D12 ERROR: CCommandList::SetGraphicsRootDescriptorTable: The currently set root signature declares parameter [1] as a descriptor table in a descriptor heap of type D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV, but the specified BaseDescriptor parameter is from a different descriptor heap type: D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER. [ EXECUTION ERROR #708: SET_DESCRIPTOR_TABLE_INVALID] D3D12: **BREAK** enabled for the previous message, which was: [ ERROR EXECUTION #708: SET_DESCRIPTOR_TABLE_INVALID ]

is there any method for restore entire state like before calling cmdList->SetDescriptorHeaps(1, &MyDescHeap);

I would be appreciated with any advices

Thanks