You need to sign in to do that
Don't have an account?
swati 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?
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.
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.
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.
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.
no it is correct,
this is my contact object's screen shot.
thnx
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.
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
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.
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
I insert data in ContactCategoryId and ContactSrno is blank, than this error is occur