
3 answers
Hi Abhilash,You are using obj.Product2.id, you need to use obj.Product2Id as per bellow code.(Same for obj.Opportunity.id , it should be obj.OpppurtunityId)
myJunctionObject obj = new myJunctionObject();
obj.Product2Id = pr.id;
obj.OpportunityId = oppty.id;
insert obj;
Additionally you missed insert statement for Product2 in your code.