• zachbarkley
  • NEWBIE
  • 309 Points
  • Member since 2013

  • Chatter
    Feed
  • 10
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 47
    Replies

Hi ...

 

I am new to sfdc ....please help me this issus

 

 

trigger HelloWorld on Account (before insert , before update) {
List<Account> aaa=Trigger.new;
MyHelloWorld my=new MyHelloWorld();
my.addHelloWorld(aaa);
}
public class MyHelloWorld{  ------------------the error show msg like  Unexpected token : public
Public void addHelloWorld( List <Account> aaa){
for(Account acc:aaa){
if(acc.Hello__c!='World'){
acc.Hello__c='World';
}
}
}
}

Hi, 

 

Below is my sample code for test class:

 

@isTest(seeAllData=true)
private class CtrlTourPlanningWithFilters_Test {
 
    static testMethod void CtrlTourPlanningWithFilters_PL_User_Test() {
        String RecTypeId= [select Id from RecordType where (Name='Person Account') and (SobjectType='Account')].Id;
 
Account Accnt = new Account(
 RecordTypeID=RecTypeId,
 FirstName='Test FName',
 LastName='Test LName',
 PersonMailingStreet='test@yahoo.com',
 PersonMailingPostalCode='12345',
 PersonMailingCity='SFO',
 PersonEmail='test@yahoo.com',
 PersonHomePhone='1234567',
 PersonMobilePhone='12345678' 
);
 
insert Accnt;
system.debug('@@@' + Accnt.isPersonAccount);
 
    }
}
 
When I check the debuglog, the "isPersonAccount" is set to false. Am I doing something that is not right?
 
Thanks,
Dane

I have two custom objects, Equipment and Equipment History. I would like to insert a new record into Equipment History when a record is inserted into Equipment. So far, I getting this error:

 

Apex trigger insertrecords caused an unexpected exception, contact your administrator: insertrecords: execution of AfterInsert caused by: System.NullPointerException: Attempt to de-reference a null object: Trigger.insertrecords: line 8, column 1

 

Here is my trigger:

trigger insertrecords on Equipment__c (after insert)
{
 Equipment__c[] eq = [SELECT Name from Equipment__c where id =: trigger.new];
 List<Equipment_History__c> copyeq;
 for(Equipment__c neweq : eq)
 
 {
  copyeq.add(new Equipment_History__c (Name=neweq.Name));
 }
 
 insert copyeq;
}

Hi everyone,

 

I also replied here but I want to make sure this gets the attention it deserves as I believe more developers are struggling with this. Since Winter 2014 there has been a shift from using the apex classes tab for testing towards using the Developer Console. This is all well and nice but it is giving me the following issues. 

 

  1. Run all tests and go to the console.
  2. Individual tests show the code coverage for some classes and triggers for that particular test in "Class Code Coverage" window.
  3. "Overall Code Coverage" window however does not show some of these triggers and classes although I can see the the code coverage in the "Class Code Coverage" window.

This is really bad. As developers we need to be able to see full overall code coverage for all triggers and classes without having to calculate this ourselves by performing each individual test and checking what gives the highest coverage.

 

What we need:

  • Being able to see the overall code coverage for ALL classes and triggers.
  • Being able to see which classes have 0% code coverage in the same list as the those that have at least 1% code coverage.
  • Being able to export this list to Excel (by CSV format or whichever is convenient).

There must be more people having the same problem, and if so, how has this been solved ? Currently I do not feel confident I can even make a reliable report with the right test percentages.

 

Thanks.

 

 

 

I have a couple of triggers on the Opportunity standard object (before and after update) which send an email and do a couple of field update.

 

I wrote a test class using Eclipse IDE. Once I run that test class I get 100% test coverage on both the triggers, however when I deploy it into my sandbox instance I get 0% on both.

 

Any advice ?

 

Below my class

 

@isTest(SeeAllData=true)
private class TestOpportunityApproval {

    static testMethod void myUnitTest() {
         
	Account account = new Account();
        account.name = 'Test Account';
        account.BillingCountry = 'myNewCountry';
        insert account;
        
        Pricebook2  standardPb = [select id, name, isActive from Pricebook2 where IsStandard = true limit 1];
        
        Pricebook2 pbk1 = new Pricebook2 (Name='Test Pricebook Entry 1',Description='Test Pricebook Entry 1', isActive=true);
		insert pbk1;

        Product2 prd1 = new Product2 (Name='Test Product Entry 1',Description='Test Product Entry 1',productCode = 'ABC',            isActive = true); 
insert prd1; PricebookEntry pbe1 = new PricebookEntry (Product2ID=prd1.id,Pricebook2ID=standardPb.id,UnitPrice=50, isActive=true); insert pbe1; Opportunity opp = new Opportunity (Name='Test_class',StageName='Prospecting',CloseDate=Date.today(),Pricebook2Id = pbe1.Pricebook2Id, AccountId = account.id ,Project_Type__c='eDiscovery',LeadSource='List',Type='New Customer - New Business',RejectionReason__c=null); insert opp; OpportunityLineItem lineItem1 = new OpportunityLineItem (OpportunityID=opp.id,PriceBookEntryID=pbe1.id, quantity=4, totalprice=200); insert lineItem1; test.startTest(); opp.RejectionReason__c='This is a test message'; opp.StageName='Order Obtained'; update opp; System.assertEquals(Opp.StageName,'Order Obtained'); test.stopTest(); } }

 

 

 

I have a fied Project_Create_Date as date field.

 

I an trying to write below code

 

 

if(Project_Create_Date__c)>'1/1/2012')

{

}

 

but it's giving me below error.

 

Comparison arguments must be compatible types: Date, String at line 103 column 19

 

Can anyone help me to resolve it?

 

 

 

Hi everyone,

 

I found a trigger online and modified it slightly. It simply edit/saves the account whenever I modify a related contact. Workflows and triggers get fired once the account has been modified afterwards.

However, I am having trouble with creating the test class. To be honest I always have issues with the "after insert, after update" test classes.

 

Can you guide me in the right direction to get the test class sorted? I checked the docs but if someone got a sample test class for after insert, after update, that would be great.

 

Here is the code:

 

trigger UpdateAccount on Contact (after update,after insert) {


        Contact [] con;
        con= Trigger.new;

set<Id> accIds = new Set <ID>();

for (Contact  ir : con) {
        
    accIds.add(ir.AccountId);

Map <ID, Contact > irforaccs = new Map <ID, Contact > (
    [select Id, accountId from Contact 
    where accountId in :accIds]);

Map<ID, Account> accsToUpdate = new Map<ID, Account> (
    [select Id  from Account
    where Id in :accIds]);

for (Account acc : accsToUpdate.values()) {
    acc.id = acc.id ;
    update acc;
}}}

 

 

If you believe you have an easier solution, then please let me know!

 

Your help is very much appreciated!

Thanks in advance,

Christian

 

Hey all,

 

I'm hoping to learn a great deal by posting here to find some expert feedback, and ideas. 

 

It's always been in the back of my mind that the more complex an application gets: the more "setup" based data is required to be populated during test classes. It seems to me that no matter how efficiently I code, follow best practices, and come up with interesting solutions: that I will eventually hit a wall  when it comes to getting (what salesforce deems) the necessary code coverage.

 

My team and I have been building an application for Supply Chain Management. It's a complex beast with many objects, and a great deal of automation and apex driven business logic. The two main application flows facilitate: Purchasing and Selling of Items.

 

This means we have complex systems surrounding pricebooks for Vendors, and Customers, warehouse/location validation, Item Databases, Bill of Materials Management, SalesOrder/Purchase Order management, Inventory Ins/Outs. There are a great deal of things that have to happen for a user to get to the final stage of one of the two main application flows. None of this is meant to happen all at once. It happens over time through a number of different user interfaces - this is basic application design for complex systems 101.

 

My issue comes when covering my code. In order to cover classes that take place at the end of one of the two previously mentioned flows: I have to essentially set up the entire organization. This includes huge numbers of DML statements/queries that have to occur in a single transaction because tests require this!

 

My question to you all is this: What secrets/tips do you have for developing complex applications and avoiding governor limits inside test classes? How do you avoid or mitigate the unnecessary overhead of re-factoring your architecture just for the needs of silly test classes that are ignored by clients during installation anyways?

 

Before you consider referring me to articles about "how to make your triggers batchable" and so on - know that I already do. There is not a single method or function in my entire application (that uses DML/Queries) that is not batchable. I use maps/sets everywhere to a point of obsession.

 

I look forward to what you all have to offer

We have to implement following things on the insert of new records :

 

  1. If Practice ID on the new record is populated:

Try to find an existing account where Context ID(Text field) on the account contains the value of Practice ID(Text) on the Custom Object.

If the value in Practice ID is less than 5 digits, add zeroes to the left of the Practice ID when comparing.

 

For example, if Practice ID is 123, try to find an account where Context ID contains ‘00123’. 

 

Note: The value in Practice ID on the Custom object shouldn’t be modified.

 

After: If we are getting any matching Accounts then create some records like create contact related to Account etc.

 

Can any one help me to achieve this functionality?

 

Thanks,

Amit

Hi, 

 

How to write a code for Email validation in apex class ....

 

this is my page

============

<apex:page controller="JstestController">
<apex:form id="myform">
<apex:pagemessages />
<apex:pageBlock id="myblock">
Email Address: <apex:inputText value="{!email}" id="email"/><br/><br/>
<apex:commandButton value="Click me!" action="{!checkEmail}"/>
</apex:pageBlock>
</apex:form>
</apex:page>

 

class

.....................

 

public class JstestController
{
public String email { get; set; }
public PageReference checkEmail()
{

}

}

 

how to wrete email validation for input text  field ....

help me.......