I am trying to update SObject record depending on the crtieria, id it matches create a SObject variable and adding values and then finally adding this into a List.When a match is found the Sobject variable here'PRrecordupdate' gets created and values get assigend but as I add it in a list,the original value already present in the list is removed and this latest PRrecordupdate get saved multiple times.Please look into the code below and let me know what I am doing wrong.Thanks
//CODE
List<Domain_review__C> newPR = new List<Domain_review__C>();
List<Domain_review__C> PRCollectionupdate = new List<Domain_review__C>();
Domain_review__C PRrecordupdate = new Domain_review__C();
map<id,domain_review__C> PRmap = new map<id,domain_review__C>();
List<Domain_Review__c> PR = [Select id,name,Property_Name_text__c from Domain_Review__c Where Exchange_Quality_ID__c =: a0W56000002PgXfEAK];
For(domain_review__c a: PR)
{
For(Domain_review__c b: newPR)
{
if(a.Property_Name_text__c == b.property_text__c)
{
PRrecordupdate.Id = a.Id;
PRrecordupdate.Approval_Status__c = b.Approval_Status__c;
PRrecordupdate.Rejection_Reason__c = b.Rejection_Reason__c;
PRrecordupdate.seller_name__c = b.seller_name__c;
PRrecordupdate.Inventory_Relationship__c = b.Inventory_Relationship__c;
PRCollectionupdate.add(PRrecordupdate);
//?? here, it's removing the earlier record and updating with new record multiple times, means at the end in PRCollectionupdate list only one record is saved multiple times//
}
}
}
PRmap.putall(PRCollectionupdate);
if(PRmap.size()>0){
update PRmap.values();
}