Skip to main content
Tweeted twitter.com/StackSalesforce/status/987270309186297858
improved formatting
Source Link
cropredy
  • 73.2k
  • 8
  • 128
  • 283

We have a scenario where we need to make assignments to fields using the method put(String, Object)

put(String, Object)

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

Once in a managed package the assignment:

String oldDesc = (String)acc.put('Custom_Field__c', 'some value');

will fail, because the packaged field will have a namespace prefix. So if it's been packaged as

'mypackage'

`mypackage`

, the correct put() call would be:

String oldDesc = (String)acc.put('mypackage__Custom_Field__c', 'some value');

How can I avoid hard coding a package namespace?

We have a scenario where we need to make assignments to fields using the method

put(String, Object)

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

Once in a managed package the assignment:

String oldDesc = (String)acc.put('Custom_Field__c', 'some value');

will fail, because the packaged field will have a namespace prefix. So if it's been packaged as

'mypackage'

, the correct put() call would be:

String oldDesc = (String)acc.put('mypackage__Custom_Field__c', 'some value');

How can I avoid hard coding a package namespace?

We have a scenario where we need to make assignments to fields using the method put(String, Object)

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

Once in a managed package the assignment:

String oldDesc = (String)acc.put('Custom_Field__c', 'some value');

will fail, because the packaged field will have a namespace prefix. So if it's been packaged as

`mypackage`

, the correct put() call would be:

String oldDesc = (String)acc.put('mypackage__Custom_Field__c', 'some value');

How can I avoid hard coding a package namespace?

We have a scenario where we need to make assignments to fields using the put(String, Object) method:

put(String, Object)

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

Once in a managed package the assignment:

String oldDesc = (String)acc.put('Custom_Field__c', 'some value');

will fail, because the packaged field will have a namespace prefix. So if it's been packaged as 'mypackage'

'mypackage'

, the correct put() call would be:

String oldDesc = (String)acc.put('mypackage__Custom_Field__c', 'some value');

How can I avoid hard coding a package namespace?

We have a scenario where we need to make assignments to fields using the put(String, Object) method:

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

Once in a managed package the assignment:

String oldDesc = (String)acc.put('Custom_Field__c', 'some value');

will fail, because the packaged field will have a namespace prefix. So if it's been packaged as 'mypackage', the correct put() call would be:

String oldDesc = (String)acc.put('mypackage__Custom_Field__c', 'some value');

How can I avoid hard coding a package namespace?

We have a scenario where we need to make assignments to fields using the method

put(String, Object)

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

Once in a managed package the assignment:

String oldDesc = (String)acc.put('Custom_Field__c', 'some value');

will fail, because the packaged field will have a namespace prefix. So if it's been packaged as

'mypackage'

, the correct put() call would be:

String oldDesc = (String)acc.put('mypackage__Custom_Field__c', 'some value');

How can I avoid hard coding a package namespace?

Source Link
powlo
  • 2.7k
  • 4
  • 30
  • 47

Apex: Getting namespace prefix

We have a scenario where we need to make assignments to fields using the put(String, Object) method:

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

Once in a managed package the assignment:

String oldDesc = (String)acc.put('Custom_Field__c', 'some value');

will fail, because the packaged field will have a namespace prefix. So if it's been packaged as 'mypackage', the correct put() call would be:

String oldDesc = (String)acc.put('mypackage__Custom_Field__c', 'some value');

How can I avoid hard coding a package namespace?