• noobfn
  • NEWBIE
  • 30 Points
  • Member since 2013

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 9
    Replies

Any thoughts on how to turn off popup from VF? I want the popUP to only show once, and when user clicks ok to remember it's response so pop up doesn't show up again when user refreshes the page or returns to this page. This is what I have in my VF and I'm toggling the checkbox showpopup in my trigger.
if({!opp.ShowPopUp__c==true})
{
var response = confirm("Click OK to clone?");

if(response==true)
{
window.parent.location.href='{!url_str}'+'{!opp.id}';
}
}

  • October 25, 2013
  • Like
  • 0

System.DmlException: Update failed. First exception on row 0 with id 006e00000049qyNAAQ; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, GlobalOpportunitySoldOrMissed: execution of AfterUpdate

caused by: System.LimitException: Apex CPU time limit exceeded

 

What does this error message mean?  

 

Thank you!

  • September 09, 2013
  • Like
  • 0

Hi,

I have no idea where my error is, debug log message is "System.NullPointerException: Attempt to de-reference a null object"  and error titled "Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, updateContactsOnAddressChange: execution of BeforeInsert" 

 

I guess I'm confused because because of my trigger before insert and after update.

 

Any help appreciate it!

 

This is my trigger: 

trigger updateContactsOnAddressChange on Account (before Insert, after update) {
     
        // I want to find the new address/values on Account by map Id Keys 
         
        Map<Id, Account> acctsWithNewAddresses = new Map<Id, Account>();
     
        // Trigger.new holds my list of the Accounts that will be updated        
        // This loop iterates over the list, and adds any that have new
        // addresses to the acctsWithNewAddresses map. 
         
        for (Integer i = 0; i < Trigger.new.size(); i++) {
            if (   (Trigger.old[i].BillingCity != Trigger.new[i].BillingCity)
                || (Trigger.old[i].BillingCountry != Trigger.new[i].BillingCountry)
                || (Trigger.old[i].BillingPostalCode != Trigger.new[i].BillingPostalCode)
                || (Trigger.old[i].BillingState != Trigger.new[i].BillingState)
                || (Trigger.old[i].BillingStreet != Trigger.new[i].BillingStreet))  {
                acctsWithNewAddresses.put(Trigger.old[i].id,Trigger.new[i]);
            }
        }
                         
        List<Contact> contacts = [SELECT id, accountid, MailingCity, MailingCountry, MailingPostalCode,MailingState, MailingStreet
                          FROM Contact
                          WHERE accountId in :acctsWithNewAddresses.keySet()];
            
                    List<Contact> updatedContacts = new List<Contact>();
     System.debug('Kellers ' + contacts);


        //iterating over each contact in Account
        for (Contact c : contacts) {
            Account parentAccount = acctsWithNewAddresses.get(c.accountId);
            c.MailingStreet = parentAccount.BillingStreet;
            c.MailingCity = parentAccount.BillingCity ;
            c.MailingCountry = parentAccount.BillingCountry ;
            c.MailingPostalCode = parentAccount.BillingPostalCode ;
            c.MailingState = parentAccount.BillingState ;
            c.MailingStreet = parentAccount.BillingStreet ;
    
     
         // Rather than insert the contacts individually, add the         
            // contacts to a list and bulk insert it. This makes the         
            // trigger run faster and allows us to avoid hitting the         
            // governor limit on DML statements 

            updatedContacts.add(c);
        }
        update updatedContacts;
    }

 This is my test: 

@isTest
public class TestUpdateContactsOnAddressChange{
    static testmethod void testAddressChange() {
       //create an account and create account address
        Account sAcct = new Account();
       	sAcct.Name = 'Test Account';
        sAcct.BillingStreet = '11 Initial Street'; 
        sAcct.BillingCity = 'Rochester';
        sAcct.BillingPostalCode = '12456';
        sAcct.BillingState = 'NY';
        sAcct.BillingCountry = 'USA';
       	 insert sAcct;
       	
                
        //create contact for Account "Test Account" and create contact address
        Contact[] sContact = new Contact[]{
        	new contact(
        MailingStreet = '1 Initial street',
       	MailingCity = 'Rochester',
        MailingPostalCode = '12456',
        MailingState = 'NY',
        MailingCountry = 'USA',
        accountid = sAcct.id),
                
        	new contact(
        MailingStreet = '2 Initial street',
        MailingCity = 'Rochester',
        MailingPostalCode = '12456',
        MailingState = 'NY',
        MailingCountry = 'USA',
        accountid = sAcct.id),
       
        	new contact(
        MailingStreet = '3 Initial street',
        MailingCity = 'Rochester',
        MailingPostalCode = '12456',
        MailingState = 'NY',
        MailingCountry = 'USA',
                accountid = sAcct.id) };
       
        insert sContact;
        
        //change address on account
        sAcct.BillingStreet = '11 Updated Street'; 
        sAcct.BillingCity = 'Updated City';
        sAcct.BillingPostalCode = '99999';
        sAcct.BillingState = 'PA';
        sAcct.BillingCountry = 'Mexico';
          
        Test.startTest();
         update sAcct;//this should fire my trigger.
        Test.stopTest();
             
               
        sContact = [Select id, accountid, MailingStreet, MailingCity,MailingPostalCode, MailingState, MailingCountry from 
                     contact where id in: sContact];
        
        //check if account updated address match each contact address
       	System.assertEquals(sAcct.BillingStreet, sContact[0].Mailingstreet); 
        System.assertEquals(sAcct.BillingCity, sContact[0].MailingCity); 
        System.assertEquals(sAcct.BillingPostalCode, sContact[0].MailingPostalCode); 
        System.assertEquals(sAcct.BillingState, sContact[0].MailingState);
        System.assertEquals(sAcct.BillingCountry, sContact[0].MailingCountry);
        
        //check addresses didn't match before update
        System.assert(sContact[1].MailingStreet != sAcct.BillingStreet); 
        System.assert(sContact[1].MailingCity != sAcct.BillingCity); 
        System.assert(sContact[1].MailingPostalCode != sAcct.BillingPostalCode); 
        System.assert(sContact[1].MailingState != sAcct.BillingState);
        System.assert(sContact[1].MailingCountry != sAcct.BillingCountry);
        
    }
}

 noobfn

  • August 02, 2013
  • Like
  • 0

Hello, I'm a noob still to all of these.  And I'm confused with my code, it doesn't work.  Initially I used a list, I was populating contacts from an Account by entering accountId & click submit button, now I want to do the same but using a FieldSet.  I created my fieldset called "properNames" and I'm stuck and confused with my code.  Can someone help?

 

VP:

<apex:page standardController="Account" extensions="fieldSetExtension">


 <apex:form >
  <apex:pageBlock >
     Enter Account Id:
   <apex:pageBlockSection >
        <apex:pageBlockSectionItem >
        <apex:inputText value="{!ContactForAcc.AccountId}" />
        <apex:commandbutton value="Submit" action="{!redirectUser}"/>
        </apex:pageBlockSectionItem>
   </apex:pageBlockSection>
     
 
   <apex:pageBlockSection columns="1" id="contactTable" title="Contats Details">
        <apex:pageBlockTable value="{!lstCon}" var="con">
        <apex:repeat value="{!$ObjectType.Contact.FieldSets.properNames}" var="f">
        <apex:column value="{!con[f]}"/>
        </apex:repeat>
        </apex:pageBlockTable>
   </apex:pageBlockSection>
   
   </apex:pageBlock>
   
 </apex:form>
 
 
</apex:page>

 Extension Controller:

public with sharing class fieldSetExtension {

    public Contact ContactForAcc {get;set;} 
    public fieldSetExtension(ApexPages.StandardController controller) {
         ContactForAcc = new Contact();
        lstCon = new List<Contact>();
         fields = new List<Schema.FieldSetMember>();
    }
    
  
  public String AccountId {get;set;}  
  Public List<Contact> lstCon {get;set;}
  Public List<Schema.FieldSetMember> fields =
     Schema.SObjectType.Contact.fieldSets.properNames.getFields();
    
    
  public PageReference redirectUser(){
   AccountId  = ContactForAcc.AccountId;
   
        if(AccountId != null)
        {
            string query = 'select';
            for(Schema.fieldSetMember f : fields){
                query += f.getFieldPath() + ', ';
            }
             query += 'id, Name from Contact where Accountid =: AccountId';
             lstCon = Database.query(query); 
        }
        
        return null;
    }
}

 Thank you so much!

I pretty new to apex, and I needed to do this trigger using map collection.  So I started and I'm stuck.  Where do i go from here?  When I create a new account the trigger should populate the account owner's email.  Thank you.

 

trigger insertEmailMap on Account (before insert, before update) {

   Map<Id, String> emailMap = new Map<Id, String>();
    
    List<User> ownerEmail = [select id, email FROM User WHERE id IN: emailMap.Keyset()];
   
    for(user u: ownerEmail){

      emailMap.put(u.id, 'email');
      system.debug(emailMap);
      }
     system.debug('map ' + emailMap);

Any thoughts on how to turn off popup from VF? I want the popUP to only show once, and when user clicks ok to remember it's response so pop up doesn't show up again when user refreshes the page or returns to this page. This is what I have in my VF and I'm toggling the checkbox showpopup in my trigger.
if({!opp.ShowPopUp__c==true})
{
var response = confirm("Click OK to clone?");

if(response==true)
{
window.parent.location.href='{!url_str}'+'{!opp.id}';
}
}

  • October 25, 2013
  • Like
  • 0

System.DmlException: Update failed. First exception on row 0 with id 006e00000049qyNAAQ; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, GlobalOpportunitySoldOrMissed: execution of AfterUpdate

caused by: System.LimitException: Apex CPU time limit exceeded

 

What does this error message mean?  

 

Thank you!

  • September 09, 2013
  • Like
  • 0

Hi,

I have no idea where my error is, debug log message is "System.NullPointerException: Attempt to de-reference a null object"  and error titled "Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, updateContactsOnAddressChange: execution of BeforeInsert" 

 

I guess I'm confused because because of my trigger before insert and after update.

 

Any help appreciate it!

 

This is my trigger: 

trigger updateContactsOnAddressChange on Account (before Insert, after update) {
     
        // I want to find the new address/values on Account by map Id Keys 
         
        Map<Id, Account> acctsWithNewAddresses = new Map<Id, Account>();
     
        // Trigger.new holds my list of the Accounts that will be updated        
        // This loop iterates over the list, and adds any that have new
        // addresses to the acctsWithNewAddresses map. 
         
        for (Integer i = 0; i < Trigger.new.size(); i++) {
            if (   (Trigger.old[i].BillingCity != Trigger.new[i].BillingCity)
                || (Trigger.old[i].BillingCountry != Trigger.new[i].BillingCountry)
                || (Trigger.old[i].BillingPostalCode != Trigger.new[i].BillingPostalCode)
                || (Trigger.old[i].BillingState != Trigger.new[i].BillingState)
                || (Trigger.old[i].BillingStreet != Trigger.new[i].BillingStreet))  {
                acctsWithNewAddresses.put(Trigger.old[i].id,Trigger.new[i]);
            }
        }
                         
        List<Contact> contacts = [SELECT id, accountid, MailingCity, MailingCountry, MailingPostalCode,MailingState, MailingStreet
                          FROM Contact
                          WHERE accountId in :acctsWithNewAddresses.keySet()];
            
                    List<Contact> updatedContacts = new List<Contact>();
     System.debug('Kellers ' + contacts);


        //iterating over each contact in Account
        for (Contact c : contacts) {
            Account parentAccount = acctsWithNewAddresses.get(c.accountId);
            c.MailingStreet = parentAccount.BillingStreet;
            c.MailingCity = parentAccount.BillingCity ;
            c.MailingCountry = parentAccount.BillingCountry ;
            c.MailingPostalCode = parentAccount.BillingPostalCode ;
            c.MailingState = parentAccount.BillingState ;
            c.MailingStreet = parentAccount.BillingStreet ;
    
     
         // Rather than insert the contacts individually, add the         
            // contacts to a list and bulk insert it. This makes the         
            // trigger run faster and allows us to avoid hitting the         
            // governor limit on DML statements 

            updatedContacts.add(c);
        }
        update updatedContacts;
    }

 This is my test: 

@isTest
public class TestUpdateContactsOnAddressChange{
    static testmethod void testAddressChange() {
       //create an account and create account address
        Account sAcct = new Account();
       	sAcct.Name = 'Test Account';
        sAcct.BillingStreet = '11 Initial Street'; 
        sAcct.BillingCity = 'Rochester';
        sAcct.BillingPostalCode = '12456';
        sAcct.BillingState = 'NY';
        sAcct.BillingCountry = 'USA';
       	 insert sAcct;
       	
                
        //create contact for Account "Test Account" and create contact address
        Contact[] sContact = new Contact[]{
        	new contact(
        MailingStreet = '1 Initial street',
       	MailingCity = 'Rochester',
        MailingPostalCode = '12456',
        MailingState = 'NY',
        MailingCountry = 'USA',
        accountid = sAcct.id),
                
        	new contact(
        MailingStreet = '2 Initial street',
        MailingCity = 'Rochester',
        MailingPostalCode = '12456',
        MailingState = 'NY',
        MailingCountry = 'USA',
        accountid = sAcct.id),
       
        	new contact(
        MailingStreet = '3 Initial street',
        MailingCity = 'Rochester',
        MailingPostalCode = '12456',
        MailingState = 'NY',
        MailingCountry = 'USA',
                accountid = sAcct.id) };
       
        insert sContact;
        
        //change address on account
        sAcct.BillingStreet = '11 Updated Street'; 
        sAcct.BillingCity = 'Updated City';
        sAcct.BillingPostalCode = '99999';
        sAcct.BillingState = 'PA';
        sAcct.BillingCountry = 'Mexico';
          
        Test.startTest();
         update sAcct;//this should fire my trigger.
        Test.stopTest();
             
               
        sContact = [Select id, accountid, MailingStreet, MailingCity,MailingPostalCode, MailingState, MailingCountry from 
                     contact where id in: sContact];
        
        //check if account updated address match each contact address
       	System.assertEquals(sAcct.BillingStreet, sContact[0].Mailingstreet); 
        System.assertEquals(sAcct.BillingCity, sContact[0].MailingCity); 
        System.assertEquals(sAcct.BillingPostalCode, sContact[0].MailingPostalCode); 
        System.assertEquals(sAcct.BillingState, sContact[0].MailingState);
        System.assertEquals(sAcct.BillingCountry, sContact[0].MailingCountry);
        
        //check addresses didn't match before update
        System.assert(sContact[1].MailingStreet != sAcct.BillingStreet); 
        System.assert(sContact[1].MailingCity != sAcct.BillingCity); 
        System.assert(sContact[1].MailingPostalCode != sAcct.BillingPostalCode); 
        System.assert(sContact[1].MailingState != sAcct.BillingState);
        System.assert(sContact[1].MailingCountry != sAcct.BillingCountry);
        
    }
}

 noobfn

  • August 02, 2013
  • Like
  • 0

Hello, I'm a noob still to all of these.  And I'm confused with my code, it doesn't work.  Initially I used a list, I was populating contacts from an Account by entering accountId & click submit button, now I want to do the same but using a FieldSet.  I created my fieldset called "properNames" and I'm stuck and confused with my code.  Can someone help?

 

VP:

<apex:page standardController="Account" extensions="fieldSetExtension">


 <apex:form >
  <apex:pageBlock >
     Enter Account Id:
   <apex:pageBlockSection >
        <apex:pageBlockSectionItem >
        <apex:inputText value="{!ContactForAcc.AccountId}" />
        <apex:commandbutton value="Submit" action="{!redirectUser}"/>
        </apex:pageBlockSectionItem>
   </apex:pageBlockSection>
     
 
   <apex:pageBlockSection columns="1" id="contactTable" title="Contats Details">
        <apex:pageBlockTable value="{!lstCon}" var="con">
        <apex:repeat value="{!$ObjectType.Contact.FieldSets.properNames}" var="f">
        <apex:column value="{!con[f]}"/>
        </apex:repeat>
        </apex:pageBlockTable>
   </apex:pageBlockSection>
   
   </apex:pageBlock>
   
 </apex:form>
 
 
</apex:page>

 Extension Controller:

public with sharing class fieldSetExtension {

    public Contact ContactForAcc {get;set;} 
    public fieldSetExtension(ApexPages.StandardController controller) {
         ContactForAcc = new Contact();
        lstCon = new List<Contact>();
         fields = new List<Schema.FieldSetMember>();
    }
    
  
  public String AccountId {get;set;}  
  Public List<Contact> lstCon {get;set;}
  Public List<Schema.FieldSetMember> fields =
     Schema.SObjectType.Contact.fieldSets.properNames.getFields();
    
    
  public PageReference redirectUser(){
   AccountId  = ContactForAcc.AccountId;
   
        if(AccountId != null)
        {
            string query = 'select';
            for(Schema.fieldSetMember f : fields){
                query += f.getFieldPath() + ', ';
            }
             query += 'id, Name from Contact where Accountid =: AccountId';
             lstCon = Database.query(query); 
        }
        
        return null;
    }
}

 Thank you so much!

I pretty new to apex, and I needed to do this trigger using map collection.  So I started and I'm stuck.  Where do i go from here?  When I create a new account the trigger should populate the account owner's email.  Thank you.

 

trigger insertEmailMap on Account (before insert, before update) {

   Map<Id, String> emailMap = new Map<Id, String>();
    
    List<User> ownerEmail = [select id, email FROM User WHERE id IN: emailMap.Keyset()];
   
    for(user u: ownerEmail){

      emailMap.put(u.id, 'email');
      system.debug(emailMap);
      }
     system.debug('map ' + emailMap);

Would someone be able to help me write a trigger so that when an account address and phone number change, the address and phone number on all contacts change?  In my perfect world, the phone number would only change on the contact IF before the update they were the same number.  Since I am not a code writer other than when I have to be, I am not sure that is even possible.

 

 

Thanks!

  • August 23, 2012
  • Like
  • 0

Hello,

 

i am currently trying to create a Visualforce page which extends the "Send an Email"-functionality.

What I would like to do is create a lookup field for an account and then automatically populate a selectList with the related contacts to that account.

 

Is this in any way possible? The most challenging thing is assigning the selected account to a variable to query the list of contacts from it. Everything else should be fairly basic stuff.

 

Maybe someone has a hint for me.

 

Regards,

hoomel

  • August 02, 2011
  • Like
  • 0