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
pradeepkumar battapradeepkumar batta 

mapping

Hi Everyone,

i am new to apex code ,i have requirement to map two objects OBJA & OBJB with same field types in two objects but there is no relationship between objects.

      OBJA                    OBJB
amount__c               Cash__c


Please Let me know how to map objects with those fields.

 
Abhishek BansalAbhishek Bansal
Hi Pradeep,

I dont know what your original requirement is but still i have written a code script for you which will help you to link the values of two objects :
Map<Decimal,OBJA__c> mapOfObjA = new Map<Decimal,OBJA__c>();
for(OBJA__c recA : [Select Amount__c form OBJA__c]){
	mapOfObjA.put(recA.Amount__c, recA);
}

for(OBJB__c recB : [Select Cash__c from OBJB__c]){
	if(mapOfObjA.containsKey(recB.Cash__c)){
		//Do your actions here......
		//You can get value in this way : recB.AnyValueWhichYouWantToChange =  mapOfObjA.get(recB.Cash__c).id;
	}
}
Please let me know if you need any further help on this.

Thanks,
Abhishek