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

Update the parent field value based on child field value using workflows/Apex
Hello Everyone,
I would like to know what should i use update a field on Account object based on chiled objects fields on account.
I Have created a Checkbox field on Account, and it needs to be True if
account division field is 'xx' and MFD field (checkbox) is 'False' then the fiel on account which i created should be True(check) and they should no longer show up as a 'abc customer'
, If not false(uncheck)..
Please suggest me how can i do this.. If i need to write a code for this please provide a smaple code for it..
Any suggestions is appriceated.
Thanks,
Nag
I would like to know what should i use update a field on Account object based on chiled objects fields on account.
I Have created a Checkbox field on Account, and it needs to be True if
account division field is 'xx' and MFD field (checkbox) is 'False' then the fiel on account which i created should be True(check) and they should no longer show up as a 'abc customer'
, If not false(uncheck)..
Please suggest me how can i do this.. If i need to write a code for this please provide a smaple code for it..
Any suggestions is appriceated.
Thanks,
Nag
Hi Nagendra kumar,
You can achieve this using formula field as well.
Please follow below steps.
1.create custom field some xxx with formula as datatype and return type as checkbox and in formula editor use below formula
Please accept my solution as Best Answer if my answer was helpful. It will make it available for other as the proper solution. If you felt I went above and beyond, u can give me kudos.
Thanks and Regards
Sandhya
I will post back when I get a chance to confirm in development environment.
Thanks Kevin for you suggestions, But i actually went through Code.
{
set<Id> SetAccIds = new set<Id>();
map<Id, id> mapAccount = new map<Id, id>();
for( Account_Salesview__c acsv : lstSalesViews )
{
if( acsv.Account__c != null )
{
setAccIds.add(acsv.Account__c);
}
}
for( Account_Salesview__c obj : [Select SalesView__r.Sales_Division__c, AccountDivision__c, Marked_for_Deletion_Flag__c, Account__c FROM Account_Salesview__c WHERE Account__c IN : setAccIds] )
{
if(obj.AccountDivision__c =='CE' && obj.Marked_for_Deletion_Flag__c == False )
{
mapAccount.put(obj.Account__c,obj.Account__c);
}
}
Account[] lstAccounts = new Account[]{};
for( Account objAcc : [Select Id, isWater__c FROM Account WHERE RecordType.Name = 'Water' AND Id IN :mapAccount.keyset()] )
{
objAcc.isWater__c = true;
//objAcc.Freight_Terms__c = string.JOIN(mapAccount.get( objAcc.Id ), ';');
lstAccounts.add(objAcc);
}
if( !lstAccounts.isEmpty() )
{
update lstAccounts;
}
}
public static void deleteIsWaterFieldOnTheAccount(Account_Salesview__c[] lstSalesViews )
{
set<Id> SetAccIds = new set<Id>();
map<Id, id> mapAccount = new map<Id, id>();
map<Id, Integer> deletedAccountIds = new map<Id, Integer>();
map<Id, Integer> allAccountIds = new map<Id, Integer>();
List<Id> lstIds = new List<Id>();
for( Account_Salesview__c acsv : lstSalesViews )
{
if( acsv.Account__c != null && acsv.AccountDivision__c =='CE' && acsv.Marked_for_Deletion_Flag__c == False )
{
setAccIds.add(acsv.Account__c);
if(!deletedAccountIds.containsKey(acsv.Account__c))
{
deletedAccountIds.put(acsv.Account__c,1);
}
else{
Integer value=deletedAccountIds.get(acsv.Account__c);
++value;
deletedAccountIds.put(acsv.Account__c,value);
}
}
}
for( Account_Salesview__c obj : [Select SalesView__r.Sales_Division__c, AccountDivision__c, Marked_for_Deletion_Flag__c, Account__c FROM Account_Salesview__c WHERE Account__c IN : setAccIds] )
{
if( obj.Account__c != null && obj .AccountDivision__c =='CE' && obj .Marked_for_Deletion_Flag__c == False )
{
//setAccIds.add(acsv.Account__c);
if(!allAccountIds.containsKey(obj.Account__c))
{
allAccountIds.put(obj.Account__c,1);
}
else{
Integer value=allAccountIds.get(obj.Account__c);
++value;
allAccountIds.put(obj.Account__c,value);
}
}
else
{
if(!allAccountIds.containsKey(obj.Account__c))
{
allAccountIds.put(obj.Account__c,0);
}
}
}