3

Quick Question, I have an soql query that looks like this:

List<Service_Instance__c> Servic = [Select Account__c, Account_Customer_Account_Number__c, Airports__c, Local_Service__c, Location__c, Terminal__c, Physical_ID__c
         from Service_Instance__c where USI__c =:usi1 limit 1];

I want to assign Account_Customer_Account_Number__c to a string for the next query I tried the following :

  AccNum = [Select Account_Customer_Account_Number__c
         from Service_Instance__c where USI__c =:usi1 limit 1];

and

  AccNum = Servic[0].Account_Customer_Account_Number__c;

I've also tried to change the AccNum from String to Integer to decimal and nothing worked.
I want to sort this out in order for this query to work :

 List<Account> AccName = [Select Name, Customer_Account_Number__c 
         from Account where Customer_Account_Number__c =:AccNum limit 1];
2
  • you are comparing Account_Customer_Account_Number__c with USI__c .Are you sure both are same. Jul 22, 2016 at 8:47
  • USI is a unique number field that Im using to get the rest of the data from the object based on that. I'm not actually using it for anything else, User types in the USI gets the details from other fields
    – user26057
    Jul 22, 2016 at 8:52

3 Answers 3

1

Viewing your code I will asume that you have declared AccNum as string (you should say it for better help)

if that is the case and viewing your error line, try to change this:

AccNum = Servic[0].Account_Customer_Account_Number__c;

for this:

AccNum = string.valueOf(Servic[0].Account_Customer_Account_Number__c);
2

Try this,

String AccNum = [Select Account_Customer_Account_Number__c
         from Service_Instance__c where USI__c =:usi1 limit 1].Account_Customer_Account_Number__c;
2
  • Yeah it just comes up with the same error as before "llegal assignment from Decimal to String "
    – user26057
    Jul 22, 2016 at 8:49
  • Change the data type of AccNum as Integer
    – Devendra
    Jul 22, 2016 at 8:51
0

Assuming that the Account__c field is a look-up to the account that you are trying to reference in your second query, I'd say the best approach is to query those fields directly in the first query:

List<Service_Instance__c> Servic = [
    SELECT Account__c, Account__r.Name, Account__r.Customer_AccountNumber__c, Account_Customer_Account_Number__c, Airports__c, Local_Service__c, Location__c, Terminal__c, Physical_ID__c
    FROM Service_Instance__c 
    WHERE USI__c =:usi1 limit 1
];

for (Service_Instance__c si : Servic){
    system.debug(si);
    system.debug(si.Account__r.Name);
}

You must log in to answer this question.