• 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';
}
}
}
}

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 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

 

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,

 

I have a requirement where i need to write a custom apex class to process a xml and then create records in salesforce.

 

One more thing, is there any way we can process a xml located in a local drive and then create records in Salesforce.

 

Please share few examples.

 

Thanks

SFDC Beginner

I am going around in circles trying to get a simple function to work in Javascript. The function looks like this:

 

<script type="text/javascript">
  function attendeeAbsent(status)
    {
      if (status == "Apologies") {
      return true;   
    }
    if (status == "Absent") {
      return true;
    }
    return false;
  }
</script>

 

I want use with to highlight a column like this:

 

<apex:column headerValue="Status" style="{!IF((attendeeAbsent(att.Status__c)),"background-color: #FFCC66;","")}">
   <apex:outputField value="{!att.Status__c}"/>
</apex:column>

 

Whatever I do, I keep getting this message when I try to save:

 

Save error: Unknown function attendeeAbsent. Check spelling.

 

Any ideas? I have been at this for almost 2 hours. I am sure its something simple, but I have very limited JS skills

 

Thanks in advance

 

 

 

 

 

public id emailtemplateid{get;set;}
//private final ApexPages.StandardController thecontroller;
public List<SelectOption> emailtemplates {
    get {
      if (emailtemplates == null) {
       emailtemplates = new List<SelectOption>();
        emailtemplates.add(new SelectOption('00Xf0000000Hzi9','Dealer Source - TEST'));
        emailtemplates.add(new SelectOption('00Xf0000000I0MT','News Snapshot'));
      }
      return emailtemplates;
    }
    set;
  }

Hi,

i want emailtempaltes as dropdown list , here i hardcoded emailtempalte ids for dropdown. please suggest me the code with out hard coding.

Hi and Thank you in advance for your help.

 

I have written a few triggers, but cannot figure this one out.   Here is my code:

 

trigger Insert_ISR onRegistration__c (afterinsert) {

 

Task[] tasks = newTask[0];

 

for(Registration__c ca: Trigger.new){

   

if(ca.Inside_Sales_Rep__c != '') {

      tasks.add(

new task(

        subject='New Registration In Progress',

        ownerid=ca.Inside_Sales_Rep__c,  --- here is the problem.  This field is a picklist which holds strings and the ownerid is an ID field.  How would you accomplish this?

        activitydate=system.today().adddays(1),

        whatid=ca.Id));

    }

  }

 

insert tasks;

}

I wrote a batch apex that selects all the records from  updated events object. When ever this batch apex is scheduled it throwing the forrlowing error:

AsyncApexExecutions Limit exceeded.

 

Following is my batch apex code.

 

 

global class SyncCalendarsUpdates implements Database.Batchable<sObject>, Database.AllowsCallouts {
    global Database.QueryLocator start(Database.BatchableContext BC) {
        String query = 'SELECT Id, Event_ID__c, Description__c, Event_Owner__r.Id, Subject__c, Start_Datetime__c, End_Datetime__c, Click_Key__c FROM Updated_Event__c';
        return Database.getQueryLocator(query);
    }
    
    global void execute(Database.BatchableContext BC, List<Updated_Event__c> scope) {
        Map<String, String> clickKeyMap = new Map<String, String>();
        for (Updated_Event__c e : scope) {
          
            Boolean doUpdate = true;
            if (e.Subject__c != null) {
                if (e.Subject__c.left(2) == 'SV' && e.Click_Key__c != null && e.Click_Key__c != '') {
                    doUpdate = false;
                }
            }
            if (doUpdate) {
                ClickCalendar cal = new ClickCalendar(e.Event_Owner__r.Id, e.Start_Datetime__c, e.End_Datetime__c, e.Subject__c, e.Click_Key__c);
                cal.buildUpdateRequest();
                if (!Test.isRunningTest()) {
                    HttpResponse resp = cal.getResponse();
                    
                  
                    if (e.Click_Key__c == null) {
                        String key = cal.getKeyFromResponse(resp);
                        if (e.Event_ID__c != null) {
                            clickKeyMap.put(e.Event_ID__c, key);
                        }
                    }
                }
            }
            e.Is_Synced__c = true;
        }
        update scope;
        
   
        List<Event> eventsToUpdate = [SELECT Id, Click_Key__c FROM Event WHERE Id IN :clickKeyMap.keySet()];
        for (Event e : eventsToUpdate) {
            e.Click_Key__c = clickKeyMap.get(e.Id);
        }
        update eventsToUpdate;
    }
    
    global void finish(Database.BatchableContext BC) { }
}

 

 

We have 1,500,000 records in that object.

How do I query for all the list view names and ids for a specific sObject via apex?

 

I don't see this in the API or as a describe object option.

 

Thanks,

 

Matt

Hello,

Im trying to SOQL query the unique profile ID from the sites object but cannot see any fields on the sites object that indicate a relationship to the related profile object.

The fields available on the site object are:

AdminId
AnalyticsTrackingCode
CreatedById
CreatedDate
DailyBandwidthLimit
DailyBandwidthUsed
DailyRequestTimeLimit
DailyRequestTimeUsed
Description
Id
LastModifiedById
LastModifiedDate
MasterLabel Default
MonthlyPageViewsEntitlement
Name
OptionsAllowHomePage
OptionsAllowStandardAnswersPages
OptionsAllowStandardIdeasPages
OptionsAllowStandardLookups
OptionsAllowStandardSearch
OptionsEnableFeeds
SiteType
Status
Subdomain
SystemModstamp
UrlPathPrefix

The answers on the forum suggest you simply use the UI button "Public Access Settings" (which take you to the profile im a trying to SOQL) to make any changes to the profile, however I cannot see in the database (via Workbench) how this relationship is constructed.

I have been through all the objects to try backward engineer the process but im coming up at dead ends.

How does a site record know which profile record is the unique profile assigned to it for the CRUD permissions.

Any help is appreciated.

Regards

Zach

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
  • October 30, 2013
  • Like
  • 0

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.

 

 

 

  • October 29, 2013
  • Like
  • 0

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

  • October 25, 2013
  • Like
  • 0

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.......

 

  • October 29, 2012
  • Like
  • 0