I have custom objects called Asset__c and Site__c. Asset__c has a lookup field to the object Site__c, which is called Asset_site__c. There is a formula field in Asset__c called Asset_Site_Name__c where the formula is Site__r.Name

when ever there is an update in asset, there is an api call which is updating the site name in a 3rd party table.

Before invoking this api call i am checking if the old site name is not equal to new site name in the asset__c object. if both are not same the api call is invoked.

Below is the code with which i am updating the Site object.

public static Id upsertSiteObject(Model m) {
  Site__c upsertedSite = new Site__c(Id=m.Id, Name = m.name , customer__c =m.custId,
     site_number__c=m.name , Industry_Type__c =m.industry , dealer__c = dealerId,
     Description__c=m.description, Latitude__c=m.latitude, Longitude__c=m.longitude);    
     upsert upsertedSite; 
     Set<id> assetids = new Set<id>();
     List<Asset__c> alist= new List<Asset__c>();
         for(Asset__c a:[SELECT id,Asset_site__c from Asset__c where site__c =:upsertedSite.Id]){
             a.Asset_site__c = upsertedSite.Id;
         system.debug('alist>>>>>>>> ' + alist);
         update alist;
     return upsertedSite.Id;    

Note: the above method is remote method and m is a wrapper.

There is a trigger on asset__c where i am calling the api call in after update. but there both the new and old values for the Asset_site_name__c is same. so the api call is not happening.

  • it would help if you can show trigger and related code also – salesforce-sas Jul 26 '19 at 11:33

Also, note that sObject fields that contain formulas return the value of the field at the time the SOQL or SOSL query was issued. Any changes to other fields that are used within the formula are not reflected in the formula field value until the record has been saved and re-queried in Apex. Like other read-only sObject fields, the values of the formula fields themselves cannot be changed in Apex. Previous Stack Exchange Question on the same topic

Salesforce official guie on SOQL and SOSL

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.