how to create a new apex class in enterprice edition(still doubt) - salesforce

hi i got a reply from u but i checked "author apex" page even though its getting problem and also i have tried in apex IDE here also i am getting this error(i.e test coverage of selected apex trigger is 0 at least 1 % test coverage is required) while moving the apex class from developer edition to enterprice edition so kindly let me know as soon as possible.

You should create a test method class that makes use of the apex trigger. This will take care of the code coverage problem. You then deploy the test class, and your new class at the same time.
Whenever you deploy to production, the system performs a "Run All Tests". So, if there are any failing tests, or if there is any insufficient code coverages, your deployment will fail.

Related

Salesforce apex not passing validation

I have two apex classes that I am trying to push to production from a sandbox. When I go to validate the change set, it fails on the code coverage part saying that the code coverage is 50% and needs to be 75%. Both of the classes have well above 75% code coverage as one class is at 100% and the other is at 95% from one of the test classes that I wrote within the sandbox. Is there something that I am missing here?
By default all local tests are run during deployment, all custom code your company written (doesn't run tests from installed managed packages. Because they're likely to fail on your required fields and these fails won't stop your deployment).
If you understand what you're doing and are under time pressure to deploy it - you can use the "run specified tests" option & list the test classes. As long as they all have 75% and all triggers being deployed have at least 1% coverage - it'll work. It'll also be quicker. You can do it in the changeset deployment UI as well as in sfdx deploy command options.
But it's a bit of "pro" move, I wouldn't do it unless you have some CI setup and something runs all tests in a sandbox from time to time. You could deploy without realising you've broken functionality you thought is unrelated. It's bit like deploying a new required field or validation rule - "what could possibly go wrong", it's just config, tests don't need to run... boom, headshot.
Proper way to do it would be to refresh sandbox from prod, deploy your code there, run all tests, keep investigating until you bring whole org back to 75%+ and then deploy that.

Apex basics - quick question on code coverage

My company hired an agency to create an MQL salesforce object. Its constructed from an Apex class with various triggers.
We no longer have a need for it, and as the standing saleforce admin, there is none at the company who knows Apex. I'm taking classes to learn it, but wanted to check in and see how I can deprecate the object from salesforce by archiving/deleting (or even just commenting out the code) to push the update to production.
Does anyone have insight into how to go about doing this? All of the courses I've taken are basic understanding of Apex and how to write small triggers, classes and queries. The agency who built the class left 0 documentation on its code.
You can't write code in production so whatever you'll try to do - will have to be done in sandbox, tested and then deployed.
There's a way to do a "destructive deployment" and really delete it but you'll need programming tools (VSCode, Eclipse IDE or Ant + Migration Tool). It's bit advanced topic, I'd suggest you hire a dev ;) or try to just comment them out.
In sandbox you can comment out the body (bodies?) of triggers and classes. You shouldn't kill whole file, leave some empty skeletons like
public with sharing class MqlGenerator{
/* kill everything
*/
}
trigger MqlTrigger on MQL__c (after insert){
/* kill everything
*/
}
Of course if there's trigger on Account and it does 10 things, only 2 of them relate to MQL then don't comment everything out ;) It'll be bit of trial and error for you, depends how clean the code is.
You will have to touch triggers, normal classes and likely unit tests too because if they did decent job - there will be tests that verify these triggers do something and now these tests will start to fail.
Add the files to changeset as you go (you do changesets, right? Doesn't sound like you deploy with Git+SFDX for example). From time to time run Apex Classes -> Compile all classes and run unit tests. Some manual testing wouldn't hurt too. If you are unsure what's left you can click on MQL's fields, there's "Where is this used?" button. Or even try clicking delete & repeating until it succeeds ;)
After you deploy this changeset...
If the MQL__c has no triggers (for example it is created in Account updates but itself doesn't have triggers), you might actually be able to delete the object. If there are related triggers, workflows etc SF will stop you. The only way to really delete it would be to run this destructive deploy. It's possible without installing anything, use the link I included and for example workbench would let you make a deployment. But it's bit "pro", if you're unsure start with commenting stuff out and maybe leave the empty skeleton until you're more comfortable. You can always hide the object's Tab, remove right to Read the object and it'll disappear from listviews, reports... it'll be an eyesore only for sysadmins.
If object has to stay around but the data storage is significant you could try truncating the object. If it gives you trouble - Data Loader, export all records (just IDs), then delete. Maybe even with hard delete option so you skip recycle bin.

Code Coverage Repeated Apex classes

We are having an issue , where when we run all tests we see some classes repeated. These classes that are repeated are actually incorrectly labeled classes.
Example: Class A and Class B. Run all tests and code coverage shows that Class A has 90% coverage and Class A has 55% coverage.
We believe this is breaking our ide, anyone know how to resolve this?
I have tried clearing the test cache (Setup > Develop > Apex Test Execution > View Test History > Clear Test Data with no change. As well i tried commenting out code that may have called the other class, still no luck.
Interestingly enough this 'bug' is present across our ide's ...dev console, welkins suite, force.com ide... Trying to pin down the cause.
It is present in all the IDE's is because it's also present in your actual Salesforce instance.
Be more specific.
Apex tests run on a server. If you do not have enough coverage you are not allowed to deploy. You probably need to add some tests to the code you'v added to the org. This could also be indication that something else is broken.

Selenium automation report

I am using Selenium framework for my test cases execution.
I need an instant report of test cases that are passed while the full suite is in execution currently.
For Eg: There are 100 test cases in suite and five have run of which 3 passed, 2 failed and I need these instant report while the suite is in-progress. Can you please help me with this task?
You can use ExtentReport.
You can use it to log your test steps and once its done it will generate a report to show your results.
For what your looking for, ExtentReport uses a "flush".
If you call this flush after each test step it will amend the step and create the report.
This is something I'm looking into myself at the moment, so I wouldn't consider this an answer but something I've stumbled across myself, hope it helps.
Here is how to set up ExtentReports on your project with examples - http://www.ontestautomation.com/creating-html-reports-for-your-selenium-tests-using-extentreports/
You must use it in conjunction with a test runner eg. TestNG or JUnit.
For what you are trying to achieve is slightly different to the example. You need to call a flush after every test step so it will amend to the report after the step is completed rather than when all the tests are completed. Its not something I have done before but it was explained to me like the following
Just call .flush() after every test instead of once at the end of your test run. BUT you need to make sure the ExtentReports object itself is only initialized once, instead of being reinitialized at the start of every test. For example, I used TestNG. The ExtentReports is called once using #BeforeSuite, but the .flush() is called after every test using #AfterMethod. I hope this makes sense.
The only thing that can’t be solved via code is the HTML refresh as this is outside the control of the ExtentReports library (it doesn’t know where you’ve opened the actual HTML file). But this can be taken care of by using a simple browser plugin as I said. At least for Chrome there are a lot of them, just do a Google search for ‘chrome auto refresh’.
Hope this helps. If you need anymore advice don't hesitate to contact me.

Salesforce - FeedbackNotificationMailbox does not compile

I am trying to run some tests. They are failing with an error of:
line -1, column -1: Previous load of class failed: feedbacknotificationmailbox
So I found FeedbackNotificationMailbox under Apex classes. Under Class Summary it says "Does Not Compile".
This is apparently part of the Salesforce.com API. So can anyone tell me how to resolve this?
Thanks.
This is most likely due to a syntax error within the FeedbackNotificationMailbox apex class. I would check the source for that class, and ensure it can be compiled independently of running your tests.
Also, you may want to check out the Force IDE for your appex development - there's built in intellisense that can warn you of these types of errors in any of your discoverable apex classes and triggers - very handy for writing and running unit tests as well.

Resources