Can anyone please help me with following issue

I am having a list of opportunity contains 3 fields value for opportunity.

List<opportunity>  listopp = new List<opportunity>( );
listopp.realdata__c = 'value1';
listopp.realdata__c = 'value2';
Insert finalList;

Now from finalList how I can get the api name of values saved in it for each record. And can save it in map.



If I understand it correctly you are looking for way to get API name of the fields populated in your Opportunity record.

Opportunity opp=new Opportunity(Name='Pikachu',Stage='CLosed');

System.debug(opp.getPopulatedFieldsAsMap().keySet()); // Prints [Name,Stage]

Src: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_sobject.htm#apex_System_SObject_getPopulatedFieldsAsMap

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.