+ Start a Discussion
Erik RodgersErik Rodgers 

Using sObject as a Map

I am fairly new to Apex and I am looking at some existing code in my Org written by a consultant. In one of our classes there is an sObject property/variable declared for a custom object. Later, in another method, I see lines of code where it appears the developer is using this sObject variable as a Map with the .put method.

Here are the declarations at the class level:

    public Apttus_Proposal__Proposal__c newQuote{get;set;}
    public String assignToParam{get;set;}
    public Id assignToValue{get;set;}

And here is the assignment statement to which I was referring:

    newQuote.put(assignToParam, assignToValue);

This makes no sense to me. Can someone please explain how this works or what it is doing to the sObject?

Thanks.

V/R,
Erik
 
Hargobind_SinghHargobind_Singh
This doesn't seem right. The newQuote is declared as an sObject and cannot be used as a Map. 

Can you check that newQuote is not declared again within the method, as a map, otherwise the compiler would have given error and not allowed to save the class.
Erik RodgersErik Rodgers
It is not declared anywhere else in any method or elsewhere in the class. It is compiled and running, so I am very confused.
sandeep sankhlasandeep sankhla
Hi Erik,

You just add one space adn again try to save the same class, it will throw you the error while saving ..if not then weneed to check the entire code why this is happening..please check and let us know the results..

Thanks,
Sandeep
Erik RodgersErik Rodgers
I can add a space and save just fine. I’d be more than happy to share the code, but it’s about 600 lines of code. I really do think this is a strange occurrence.