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
saasteamsaasteam 

Editing account data

Hi all,

 

I call an external web service and I would like to write the answer into an account's field.

By now I'm able to do the callout and I get the response and to edit account's field I use a query. But I'm forced to use a particular name of the account.

The cose is the following:

 

String r = np.GetPrimeNumbers(8);

               String varName = 'Test triggerB';         

               Account[] la = [select Name, Phone, Fax, Account_Credit_Check__c from Account where name = :varName];

 

I'm forced to use Test triggerB as account name. How can I call the field account name, instead of its value?

Best Answer chosen by Admin (Salesforce Developers) 
WhyserWhyser

See that makes things much easier now

 

sforce.apex.execute( ("ExpWsNumeriPrimi", "recuperaNumeriPrimi",{AccountId:"{!Account.Id}"});

 

 

And you'll have to update your method to take in the AccountId, methodName ( Id AccountId )

All Answers

WhyserWhyser

I don't think I quite follow what you're asking for.

What kind of answer does your webservice return? And what are field you planning to write into the account? And how do you know which account to write to?

saasteamsaasteam

web  service resturns a string. For example I would like to write the string value into account's phone field.

How can I do this?

 

SuperfellSuperfell

Account a = new Account(Id='whatever the accounts id is');

a.phone = theResultOfYourWebServiceCall;

update a; 

saasteamsaasteam

Thanks a lot!

 

But what if I have an already exiting account?

I create an account in Account tab. Then by a function button I make a callout to an exetrnal Web Service that returns account's phone number. Now I need to edit the field phone number for the already exsiting account. How can I do it?

 

 

SuperfellSuperfell
The code i posted does update an existing account, you just need the ID of the existing record.
saasteamsaasteam

I'm trying to biuld up a code that updates a generic account. I need to know if there's a way to get the account id, from an existing record. I don't want to write account id in the code, but from a code line I want to get an account id.

How do I get the account id if I don't know it?

 

This is my code. Line 8 is the way that I'm using now: I put a fixed value into a variable. Line 9 shows you what I would like to do: use a method to get account name (or id).

 

Is line 9 correct? What should I have to use?

global class ExpWsNumeriPrimi {
public static Account acc;
@future (callout=true)
webservice static void recuperaNumeriPrimi() {

microsoftComWebservices.PrimeNumbersSoap np = new microsoftComWebservices.PrimeNumbersSoap();

String r = np.GetPrimeNumbers(8);

// parametrizzo la stringa 'Test triggerB'
String varName = 'Test triggerB';
//String varName = this.get(name);
// utilizzo il parametro nella where condition della query e memorizzo il risultato in un array
Account[] la = [select Name, Phone, Fax, Account_Credit_Check__c from Account where name = :varName];
la[0].fax = la[0].fax+'7';
if (r=='1,3,5,7'){
//la[0].Credit_Check__c = 'Yes';
la[0].Account_Credit_Check__c = true;
} else {
//la[0].Credit_Check__c = 'No';
la[0].Account_Credit_Check__c = false;
}

update(la);

}

}

 

 Thanks once more!

WhyserWhyser

See this is the part where I'm confused. I understand that you wanted to update a field on the Account, but you don't know which Account you want to update, or at least you don't seem to have a starting point on figuring out which Account to use.

My question to you is now, how is being called? or where is it being called from?

One of the things you can do is pass in the Account OR the Account ID into your method call "recuperaNumeriPrimi( Account a )" and you can refer to the variable "a" in your method, thus avoiding having to do a query call in your method to get details of the Account.

But like I said, it depends on how you are calling this method... does the caller of the method know what the Account is?

saasteamsaasteam

that's  the point.

i call this class by a custom button from a generic account layout.

 

so i wish to have a method, or a way to pass the account detail (name or Id could be the same) to my class.

 

I am in the details page of the Account Jhon Doe.

how can i pass the account ID if this is the custom button funtion?

{!REQUIRESCRIPT("/soap/ajax/15.0/connection.js")} {!REQUIRESCRIPT("/soap/ajax/15.0/apex.js")} sforce.apex.execute("ExpWsNumeriPrimi", "recuperaNumeriPrimi", {});

 

 

 


 

 

SuperfellSuperfell
Whatever is calling this code should pass the accountId into it.
WhyserWhyser

See that makes things much easier now

 

sforce.apex.execute( ("ExpWsNumeriPrimi", "recuperaNumeriPrimi",{AccountId:"{!Account.Id}"});

 

 

And you'll have to update your method to take in the AccountId, methodName ( Id AccountId )

This was selected as the best answer
saasteamsaasteam

Ok,everything is going right!

 

Thanks a lot!

 

Ciao!!