You need to sign in to do that
Don't have an account?
Praveen Yadavalli 17
Saving a Salesforce Standard required field with formula logic using workflow rule IF field is left blank by overcoming the validation
Hi
I have a requiremnt where there is a standard object OPPORTUNITIES we had a business scenario where opportunity name should over ride with the name which is used in field update by using work flow while creation of record. the business got back to me and changed the requiremnt like if the user does not enter any value in the required field on standard opportunity object and try to save it then it should bring the fieldupdate by using workflow or in case2 if user gives some some name it should directly take that name.
I am good with second scenario by just going in to the work flow and make it checked "every time when record is created" use this work flow the problem comes next how to overcome to save a field (Standard Required field) without giving value in it and make it over ride by field update value, I tried with below code but its not going through. please help me out with your suggestions.
List<Opportunity> lstOpps = new List<Opportunity>();
Set<Id> setAccountIds = new Set<Id>();
if(Trigger.isInsert && Trigger.isBefore) {
for(Opportunity o: Trigger.new){
lstOpps.add(o);
setAccountIds.add(o.AccountId);
if(String.isBlank(o.Name) && !rtMapById.get(o.RecordTypeId).getName().containsIgnoreCase('National')){
//lstOpps.add(o);
//setAccountIds.add(o.AccountId);
//o.Name = rtMapById.get(o.RecordTypeId).getName()+'-'+o.AccountId+'-'+Date.today().format();
}
}
Map<Id, Account> mapAccounts = new Map<Id,Account>([select id,name from Account where id in : setAccountIds]);
for(Opportunity o: Trigger.new){
o.Name = rtMapById.get(o.RecordTypeId).getName()+'-'+mapAccounts.get(o.AccountId).Name+'-'+Date.today().format();
}
I have a requiremnt where there is a standard object OPPORTUNITIES we had a business scenario where opportunity name should over ride with the name which is used in field update by using work flow while creation of record. the business got back to me and changed the requiremnt like if the user does not enter any value in the required field on standard opportunity object and try to save it then it should bring the fieldupdate by using workflow or in case2 if user gives some some name it should directly take that name.
I am good with second scenario by just going in to the work flow and make it checked "every time when record is created" use this work flow the problem comes next how to overcome to save a field (Standard Required field) without giving value in it and make it over ride by field update value, I tried with below code but its not going through. please help me out with your suggestions.
List<Opportunity> lstOpps = new List<Opportunity>();
Set<Id> setAccountIds = new Set<Id>();
if(Trigger.isInsert && Trigger.isBefore) {
for(Opportunity o: Trigger.new){
lstOpps.add(o);
setAccountIds.add(o.AccountId);
if(String.isBlank(o.Name) && !rtMapById.get(o.RecordTypeId).getName().containsIgnoreCase('National')){
//lstOpps.add(o);
//setAccountIds.add(o.AccountId);
//o.Name = rtMapById.get(o.RecordTypeId).getName()+'-'+o.AccountId+'-'+Date.today().format();
}
}
Map<Id, Account> mapAccounts = new Map<Id,Account>([select id,name from Account where id in : setAccountIds]);
for(Opportunity o: Trigger.new){
o.Name = rtMapById.get(o.RecordTypeId).getName()+'-'+mapAccounts.get(o.AccountId).Name+'-'+Date.today().format();
}
If I understand your requirement right, You are expecting to save record with blank name for Opportunity and let Trigger/WF to update the value if name is blank. Opportunity name is standard Salesforce field and required universally. As far as I know, You can not save opportunity with blank name. Triggers/WF rules will run only after DML operation on record (Saving record).
Thanks
All Answers
As per standard Salesforce behavior, WF rules bypasses the validation rules. Also,in sequence execution, wf executes after the before and after trigger, so it might overriding the value you have provided in trigger.
I would suggest to put this population logic in trogger only, and remove WF completely.
Please mark this as best ans if this helps!!
If I understand your requirement right, You are expecting to save record with blank name for Opportunity and let Trigger/WF to update the value if name is blank. Opportunity name is standard Salesforce field and required universally. As far as I know, You can not save opportunity with blank name. Triggers/WF rules will run only after DML operation on record (Saving record).
Thanks