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

errorin trigger
Hi I am having this trigger . when my account name is already present status will updated as Y . and when address is already present then its not updating to Y .. why ?
trigger accountupdatestatus1 on Account (before insert) {
list<account> acc = new list<account>();
list<account> acc1 = new list<account>();
for(account a: trigger.new)
{
acc=[select id,name from account where name=:a.name];
if(acc.size()>0)
{
a.Status__c = 'Y' ;
}
}
for(account a1: trigger.new)
{
acc1=[select id,name,BillingStreet from account where name=:a1.BillingStreet];
if(acc1.size()>0)
{
a1.Status__c = 'Y' ;
}
}
}
trigger accountupdatestatus1 on Account (before insert) {
list<account> acc = new list<account>();
list<account> acc1 = new list<account>();
for(account a: trigger.new)
{
acc=[select id,name from account where name=:a.name];
if(acc.size()>0)
{
a.Status__c = 'Y' ;
}
}
for(account a1: trigger.new)
{
acc1=[select id,name,BillingStreet from account where name=:a1.BillingStreet];
if(acc1.size()>0)
{
a1.Status__c = 'Y' ;
}
}
}
Couple of things before you approach this problem-
- Account Name field is mandatory. So, your condition should have been if (a.BillingStreet != '') to change the status
- You have written SOQL queries in for loop. Its a poor practice. You would get Error 101 if you use bulk imports.
Hint: If you follow step 1, you need only 1 for loop! Give it a try, you are not able to resolve, I'm happy to help.Can you take a moment to upvote and mark this answer as solved, if it helped you.
Cheers!
Ajinkya Deshmukh
1 - when account name present then insert the record and update status as Y
2- when address is present then insert the record and update status as Y
could you please change the code so that i can get a good idea how to query outside for loop
This should work-
Note: Put some condition in the else block below, else your status would always be Y
Can you take a moment to upvote and mark this answer as solved, if it helped you.
Cheers!
Ajinkya Deshmukh