You need to sign in to do that
Don't have an account?
Problem in querying standard field value of custom object
Hi frnds,
In this Rental_detail__c (custom object), I created a standard field (ID) with autonumber format {0}.
Now I am inserting a record and I want the ID after insertion, so i thought of querying Max(ID).
I tried this part of code in my controller expecting it to return serial number, but is returning a random string (a0B900000022W9aEAE)
List<AggregateResult> groupedResults = [SELECT MAX(ID)maxval FROM Rental_detail__c];
String newId;
if(groupedResults .size() > 0) {
newId = ''+groupedResults[0].get('maxval') ;
}
System.debug('New id:'+newId);
Pls help me on this.
once a record is inserted, you will be getting the ID,Name as by default. ID--Which is system generated one and Name(Based on DataType, Text,AutoNumber). How do you created a ID field ?
So in this your case, You need to get the Name field instead ID,
Try this.
All Answers
once a record is inserted, you will be getting the ID,Name as by default. ID--Which is system generated one and Name(Based on DataType, Text,AutoNumber). How do you created a ID field ?
So in this your case, You need to get the Name field instead ID,
Try this.
Just to add one more thing - that isn't a random string, that is the unique Salesforce id for the record.
The first 3 characters (a0B) identify the type of sobject - in this case your Rental_Detail__c custom sobject.
The next 12 characters form the remainder of the id.
The final 3 characters are added to make the id case-insensitive when used in external systems.
Thanks for the help and explanation.
Hi,
I have a doubt, So if want to query data w.r.t the standard field, how should I refer to it,
i.e using field label or name
field label is BookingID
field name is Name
select No_of_Days__c from Rental_detail__c where BookingID=:30
or
select No_of_Days__c from Rental_detail__c where Name=:30
Thanks,
Sowjanya
You'd query on the field name (that is the API name) - the label is the friendly text that is displayed to users.