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
Austin_SteveAustin_Steve 

Test coverage of selected Apex Trigger is 0%, at least 1% test coverage is required?????

I am getting the error above.  The code is below. I have systematically removed all code from this trigger to try and pinpoint what is generating this error. This what is left and it still generates the error;

 

 

trigger UpdCnt on Account (after update) {
List<Contact> cnt = new List<Contact>();
}

Obviously this trigger does nothing.  If I take out the one line that's in there it will Save to the Server.  

 

Any suggestions?

 

Austin_Steve

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
Jon Mountjoy_Jon Mountjoy_

Hello Austin_Steve 

 

The problem isn't with your trigger code itself.  Check out what the error message says "Test coverage of selected Apex Trigger...".  ie. this is about "Test coverage".

 

Doing a search (top right) I found this post - check out its Solution:

http://community.salesforce.com/sforce/board/message?board.id=apex&message.id=6046#M6046

 

You'll notice they've got another class that creates an instance of the object, inserts it, and verifies that the trigger's actions are called out.  Also check out this article  An Introduction to Apex Code Test Methods.

 

Hope that helps

Jon 

 

 

All Answers

Jon Mountjoy_Jon Mountjoy_

Hello Austin_Steve 

 

The problem isn't with your trigger code itself.  Check out what the error message says "Test coverage of selected Apex Trigger...".  ie. this is about "Test coverage".

 

Doing a search (top right) I found this post - check out its Solution:

http://community.salesforce.com/sforce/board/message?board.id=apex&message.id=6046#M6046

 

You'll notice they've got another class that creates an instance of the object, inserts it, and verifies that the trigger's actions are called out.  Also check out this article  An Introduction to Apex Code Test Methods.

 

Hope that helps

Jon 

 

 

This was selected as the best answer
mohimohi
 dear Sir i want to use javascript on  
ChkValidate buttoon clik to validate input text Resedency
<apex:page id="ats" controller="opportunityController" tabStyle="Opportunity">

<apex:sectionHeader title="new Customer Opportunity" subtitle="Step 1 to 3"/>
<h1>Congratulations</h1>
<apex:form id="firstpage">
<apex:pageBlock title="Customers Information">
<apex:facet name="footer">
<apex:outputPanel >
<apex:commandButton action="{!Step2}" value="next" styleClass="btn" />
<apex:commandButton value="ChkValidate" onclick="validateresedency();" />
</apex:outputPanel>
</apex:facet>
<apex:pageblockSection title="Account Information">
<apex:panelGrid columns="2">
<apex:outputLabel value="Account Name" for="accountName"></apex:outputLabel>
<apex:inputField id="accountName" value="{!account.name}"/>
<apex:outputLabel value="site" for="accountSite"></apex:outputLabel>
<apex:inputField id="accountSite" value="{!account.site}"/>
</apex:panelGrid>
</apex:pageblockSection>
<apex:pageblockSection title="Contact Information">
<apex:panelGrid columns="2">
<apex:outputLabel value="First Name" for="contactFirstName"></apex:outputLabel>
<apex:inputField id="contactFirstName" required="true" value="{!contact.firstName}"/>
<apex:outputLabel value="Last Name" for="contactLastName"></apex:outputLabel>
<apex:inputField id="contactLastName" value="{!contact.lastName}"/>
<apex:outputLabel value="Phone" for="contactPhone" ></apex:outputLabel>
<apex:inputField id="contactPhone" required="true" value="{!contact.Phone}"/>
<apex:outputLabel value="Residence"></apex:outputLabel>
<apex:inputText id="Residency" />
</apex:panelGrid>
</apex:pageblockSection>
</apex:pageBlock>
<script>
function validateresedency()
{
var av=document.getElementById("{!$Component.ats.firstpage.Residency}").value;
if(av=="")
{
alert('Plz Enter a valid Number');
}
}
</script>
</apex:form>



</apex:page>
Jon Mountjoy_Jon Mountjoy_

Hi Mohi

 

Your question has nothing to do with Triggers, which is what this thread is about.  To stand more of a chance of someone finding your question and answering it, I suggest posting it to the Visualforce board.

 

Thanks!

Jon 

justinpauldavis10justinpauldavis10

I have a similar question that I'm hoping someone will help me with, I'm new to Apex.

I have a very simple lookup-field trigger that places a record ID in that field, on a custom "Accounts" object, not the standard object:


trigger SetAccountField on Account__c (before insert, before update) {
    for (Account__c Account__c : Trigger.new) {
        a.Scoring__c = 'a00A0000003MnLw';
    }
 }


How can I create a test class, for something like this? Can you give me an example of the best way to test something this simple?