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
Namrata HeggadalNamrata Heggadal 

Adding Namespace to the code

While moving code from developer org to packaging org using ANT in few places of the apex code we need to prefix the packaging namespace. Is there any way to automate this process?
For instance:
RecordType Test = [ SELECT Id, Name FROM RecordType WHERE SobjectType = 'abc__books__c' AND DeveloperName = 'bookreview' ];
In the above code abc is the namespace which is added manually.
NagendraNagendra (Salesforce Developers) 
Hi Namrata,

First and foremost sincerely regret delayed reply.

For this you need to create a common class where you declare the namespace as private variable like this:
private static String NAMESPACE_PREFIX='abc';
Then you use this variable wherever you need this prefix like in your case:
String sObject = NAMESPACE_PREFIX+'books__c'; String devName = books; String qry = '[select Id,Name from RecordType where SobjectType = :sObject and DeveloperName = :devName]
Hope this helps.

Regards,
Nagendra.P