function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
praveen kumar 110praveen kumar 110 

Can any out help me the below code

list<account>  lstaccout=[select name,phone,billingaddress from account where name='test' and phone='999999999' and address='test'];    am getting the list from out source with out id   i want to check it  in my account list if account is there update other wise upsert  the list of accounts
Neetu_BansalNeetu_Bansal
Hi Praveen,

As per my understanding, I guess you want to check in database if any Account exist with Name = Test, Phone = 999999999 and Address = Test. If yes, you want to update some fields on that Account, If no, you want to create new Account.

So you should try this:
List<Account> lstAccount = [ Select Name, Phone, BillingAddress from Account where Name='test' and Phone='999999999' and ( BillingStreet = 'test' OR BillingCity = 'test' OR BillingState = 'test' OR BillingCountry = 'test' ) ];

if( lstAccount.size() > 0 )
{
      // Update the account field (Note: It should be query)
     update lstAccount;
}
else
{
   Account acc = new Account( Name='test', Phone='999999999', BillingStreet = 'test' );
   insert acc;
}

Please let me know if it resolve your problem.

If it helps, please mark it as the Answer, so it would help others too.

Thanks,
Neetu
praveen kumar 110praveen kumar 110
Hi Neetu, 
Thank you for posting.

I am getting the list with out id so am unble to do "update lstAccount;" , we have to query same condition in our account database get those id's update it,if the data is not thare for specifice condition we need to create new one.

Thanks,
Praveen.

 
Neetu_BansalNeetu_Bansal
I am not able to understand your requirement. Can you please elaborate?

Thanks,
Neetu