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
niki s 7niki s 7 

How to pass hard-coded value

Hello in account object there is a field called xyz and in that field I want to pass hard-coded value.. what is the easiest way to achieve this.. please help
Suraj Tripathi 47Suraj Tripathi 47
Hi,

By using apex you can simply fetch account in query:-
 
List<account> acList=[select id, xyz from account];
if(acList.size()>0)
{
for(account a: acList){
a.xyz = 'default value';
}
}
      update aclist;
Please mark it as Best Answer if it helps you.

Thanks & Regards
Suraj Tripathi




 
CharuDuttCharuDutt
Hii Niks
Try Below Code
List<account> lstAcc=[select id,Name, xyz__c from account];

list<Account> updatelist = new list<Account>();
for(account acc: lstAcc){
acc.xyz = 'default value';
updatelist.add(acc);
}
update updatelist ;
Please Mark It As Best Answer If It Helps
Thank You!
niki s 7niki s 7
Can we do it using out of the box functionality ?? Question is like whenever a new account is created I want to update xyz with a constant value
CharuDuttCharuDutt
Hii Nikis
You Can Try Trigger Or Method In The Image Shown Below
trigger ConstantValue on Account (before insert) {
String DefaultValue = 'Test Value';   
if(Trigger.IsBefore && Tigger.IsInsert){
for(Account Acc:trigger.new){
Acc.xyz__c =  DefaultValue;
}
    }
Go To Object Manager Select Account Object Select xyz Field To Edit And Do As Shown In Image
User-added image 
Please Mark It As Best Answer If It Helps
Thank You!

 
Suraj Tripathi 47Suraj Tripathi 47
Hi,

One of the ways is to create a trigger on Account:-
    
trigger AccountTrigger on Account (before inser) {
String valueOfDefault = 'Any Value';   
if(Trigger.IsBefore){
   if(Tigger.IsInsert){
     for(Account A:trigger.new){
         A.xyz =  valueOfDefault ;
       }
     }
   }
}
Please mark it as Best Answer if it helps you.

Thanks & Regards
Suraj Tripathi