How to add new lead and update an existing lead in apex?

How to add new lead and update an existing lead in apex?

I would like to kow how I can search my database (saleforce’s leads and contacts) and update existing user’s info. You should execute a query on lead and contact using the email address as the criteria for you query. If it returns 0 records for the Lead and 0 records for the Contact, then you would create a new Lead.

How to execute a query on lead and contact?

You should execute a query on lead and contact using the email address as the criteria for you query. If it returns 0 records for the Lead and 0 records for the Contact, then you would create a new Lead. Your query could return more than 1 record for either Lead or Contact, so you will have to develop a strategy to handle that case.

Can you run Apex code under another user?

The runAs method doesn’t enforce user permissions or field-level permissions, only record sharing. You can use runAs only in test methods. I have not found any exception to this rule, nor any workaround.

Do you have to specify owner to convert lead?

Optionally, when converting leads owned by a queue, the owner must be specified. This is because accounts and contacts can’t be owned by a queue. Even if you are specifying an existing account or contact, you must still specify an owner. This example shows how to use the Database.convertLead method to convert a lead.

How to write test class for this apex class and?

1. Test class must start with @isTest annotation if class class version is more than 25 2. Test environment support @testVisible , @testSetUp as well 3. Unit test is to test particular piece of code working properly or not . 4. Unit test method takes no argument ,commit no data to database ,send no email ,flagged with testMethod keyword .

How to write test class for update lead scenario?

Please check below post to learn test classes. 1. Test class must start with @isTest annotation if class class version is more than 25 2. Test environment support @testVisible , @testSetUp as well 3. Unit test is to test particular piece of code working properly or not .