You need to sign in to do that
Don't have an account?

This trigger is not updating the moblile filed?.
trigger mobileUpdate on APEX_TEST__c (before insert, after insert, after update, before update) { List<APEX_TEST__c> mobile = new List<APEX_TEST__c>(); for(APEX_TEST__c m : mobile){ m.mobile__c = '9413836278'; } insert mobile; }
I want to update mobile filed for all record. any help??
trigger mobileUpdate on APEX_TEST__c (before insert, after update) {
List<APEX_TEST__c> listtoupdate = new List<APEX_TEST__c>();
If(Trigger.isInsert && Trigger.isBefore){
for(APEX_TEST__c m : Trigger.new){
m.mobile__c = '9413836278';
}
}
If(Trigger.isUpdate && Trigger.isAfter){
for(APEX_TEST__c m : Trigger.new){
m.mobile__c = '9413836278';
listtoupdate.add(listtoupdate);
}
if(listtoupdate.size() > 0){
update listtoupdate;
}
}
Please mark it as best answer if this helps you
All Answers
trigger mobileUpdate on APEX_TEST__c (before insert, after update) {
List<APEX_TEST__c> listtoupdate = new List<APEX_TEST__c>();
If(Trigger.isInsert && Trigger.isBefore){
for(APEX_TEST__c m : Trigger.new){
m.mobile__c = '9413836278';
}
}
If(Trigger.isUpdate && Trigger.isAfter){
for(APEX_TEST__c m : Trigger.new){
m.mobile__c = '9413836278';
listtoupdate.add(listtoupdate);
}
if(listtoupdate.size() > 0){
update listtoupdate;
}
}
Please mark it as best answer if this helps you
Error:
mobileUpdate: execution of AfterUpdate caused by: System.FinalException: Record is read-only Trigger.mobileUpdate: line 24, column 1
whiich is m.mobile__c = '9413836278';
trigger mobileUpdate on Account (before insert, before update) {
List<Account> listtoupdate = new List<Account>();
If(Trigger.isInsert && Trigger.isBefore){
for(Account m : Trigger.new){
m.Phone = '9413836278';
}
}
If(Trigger.isUpdate && Trigger.isbefore){
for(Account m : Trigger.new){
m.Phone = '9413836278';
}
}
}