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
swati joshi 14swati joshi 14 

I generate some custom fields in contact object, now how can i wirte query to get data from SOQL

I generate some custom fields in contact object, now how can i wirte query to get data from SOQL?
vineet kumarvineet kumar
Hi Swati,

Suppose you have created some custom fields as Mobile__c, Contact_Source__c on Contact.

// SOQL Query
List<Contact> contactList = [SELECT Mobile__c, Contact_Source__c   FROM Contact ];

Please find the SOQL and SOSL Reference link below:
https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql.htm

Thanks.
Deepali KulshresthaDeepali Kulshrestha
Hi swati,
Greetings to you!

- I read your problem and implemented in my Org.    
- Here I am sharing SOQL query for your problem [solved].

Note: - Custom fields always have (Double underscore c)__c at the end.

- I created some custom fields on Standart object 'Contact' : -

a) Alter Number (Type - text, api - Alter_Number__c)
b) Nick Name (Type - text, api - Nick_Name__c)

- You have to create some records for it.
    
    Contact contactRecord=new Contact();
    contactRecord.Alter_Number__c='85236479561';
    contactRecord.Nick_Name__c='Bob Test';
    insert contactRecord;

- Now you have a record in contact with new custom fields.
- To retrieve the data from custom fields below query is helpful.

List<Contact> conList=[SELECT Name,Nick_Name__c,Alter_Number__c FROM Contact LIMIT 10000];
System.debug('Records -->'+conList);
    
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Deepali Kulshrestha.
swati joshi 14swati joshi 14
Hi Vineet,

Thnx for reply. but this is still not running, getting error-
"
SELECT MRGuide__ContactSrNo__c   FROM Contact
       ^
ERROR at Row:1:Column:8
No such column 'MRGuide__ContactSrNo__c' on entity 'Contact'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names."

where MRGuide is namespace of my org.

Thnx in advance.
vineet kumarvineet kumar
Swati,

I guess the field's API name is incorrect in the query.

Follow the below link to check API name:
https://support.prontoforms.com/hc/en-us/articles/217496578-API-Names-of-Salesforce-Custom-Objects-and-Custom-Fields

Thanks.
swati joshi 14swati joshi 14
Hi Vineet,

no it is correct,
this is contact object

this is my contact object's screen shot.

thnx
 
vineet kumarvineet kumar
Swati,

Check the field-level security for the current logged in user's profile.

If accessibility is not given to the user profile, then give access to the user profile on the concerning field.

Thanks.
swati joshi 14swati joshi 14
Hi Deepali Kulshrestha,

It works, but if we doesn't have any value in custom field then how can we get remaining fields value by query.

Thanks
Swati Joshi
Deepali KulshresthaDeepali Kulshrestha
Hi swati,
Greetings to you!

- Suppose custom feild 'Alter_Number__c' has no value.

List<Contact> conList=[SELECT Name,Nick_Name__c,Alter_Number__c FROM Contact LIMIT 10000];

- And we do a query for it and print this list.

System.debug('Contact List-->'+conList);

- So the output will be like this.

Contact List--> ["Name":test,"Nick_Name__c": ,"Alter_Number__c":85236479561]

- It will display blank for it.
    
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Deepali Kulshrestha.
swati joshi 14swati joshi 14
Hi Deepali!
Namaste!!

Thanks for reply, but I am getting the same error.

MRGuide__ContactCategoryId__c,MRGuide__ContactSrNo__c from Contact
                              ^
ERROR at Row:1:Column:46
No such column 'MRGuide__ContactSrNo__c' on entity 'Contact'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names.

Thnx in advance.
Swati Joshi
swati joshi 14swati joshi 14
Hi,
I insert data in ContactCategoryId and ContactSrno is blank, than this error is occur