You need to sign in to do that
Don't have an account?
Avinash@salesforce
Trigger to make only one check box True
Hi friends,
I have 1 custom object (Dimensions__c) which has a lookup relationship with Account standard object (Dimensions__c is Child).
There is a chechbox on Dimension__c (Repayment_Enabled__c).
Now wehenever i create a dimension this check box is made true automatically.
What my need is that, there should be only one check box true on for a record related to account.
Even though there may be 5 dimension records which are related to 1 account but checkbox should be true for only 1 dimension record.
I have tried this one, But struck.
As i am new to development Please help me.
trigger Primarycheck on Account (before insert,before update,after insert) {
List<Account> acct = new List<Account>();
Set<Id> vwoid = new Set<Id>();
List<Dimensions__c> vwo = new List<Dimensions__c>(); // my custom object
for(Account a : trigger.new){
if(Repayment_Enabled__c[0] == 'true'){ // this is the check box field which needs to be true for only one record related account
Repayment_Enabled__c[1] = false;
}
}
How to solve this one.
Any help friends..!
}
I have 1 custom object (Dimensions__c) which has a lookup relationship with Account standard object (Dimensions__c is Child).
There is a chechbox on Dimension__c (Repayment_Enabled__c).
Now wehenever i create a dimension this check box is made true automatically.
What my need is that, there should be only one check box true on for a record related to account.
Even though there may be 5 dimension records which are related to 1 account but checkbox should be true for only 1 dimension record.
I have tried this one, But struck.
As i am new to development Please help me.
trigger Primarycheck on Account (before insert,before update,after insert) {
List<Account> acct = new List<Account>();
Set<Id> vwoid = new Set<Id>();
List<Dimensions__c> vwo = new List<Dimensions__c>(); // my custom object
for(Account a : trigger.new){
if(Repayment_Enabled__c[0] == 'true'){ // this is the check box field which needs to be true for only one record related account
Repayment_Enabled__c[1] = false;
}
}
How to solve this one.
Any help friends..!
}
I am assuming that you want to keep the most recently updated/inserted Dimensions__c record to have checkbox=true & all other records to have checkbox = false.
Mark this as Best Answer, if this solves your problem.
All Answers
I am assuming that you want to keep the most recently updated/inserted Dimensions__c record to have checkbox=true & all other records to have checkbox = false.
Mark this as Best Answer, if this solves your problem.
I have a similar request but mine is for a related list called Placements on the contact where I have populated all historical data marking the record with the earliest start date as true, however I need to look the this field so that if a new record is created then the field called First Scotland Placement is not available.
I would be grateful for any advice.
Lorr
Your code works perfect even i had same kind of scenario. Thanks.