• poojaa
  • NEWBIE
  • 40 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 11
    Replies
Hi,

The below trigger was fired after updating the field twice, but it was not fired before update.
 
trigger age on Account (before update) {

  Map<Id,Account> ageMap = new Map<Id,Account>(); 
  Account[] acct = [SELECT Id,Age__c FROM Account WHERE Id IN : Trigger.newMap.keySet()];
    
     for(Account a : trigger.new){
           

            if(a.age__c != null){
             
                ageMap.get(a.Id);
                a.Is_Age_Updated__c = true;
               
            }
            else{
                
             ageMap.get(a.Id);
             a.Is_Age_Updated__c = false;
            }                  
    }

}


 
  • February 02, 2018
  • Like
  • 0
I'm unable to deploy my big object due to the error as shown below. I have created the package, but it has thrown the below error.
User-added image

My zip folder
User-added image

Package.xml
 
<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
    <types>
        <members>rider_history__b</members>
        <name>CustomObject</name>
    </types>
    <types>
        <members>rider_history</members>
        <name>PermissionSet</name>
    </types>
    <version>41.0</version>
</Package>

Please guide me regarding the issue
  • January 25, 2018
  • Like
  • 0
Hi
I have created an apex trigger to update contact address when the account address is changed. The code worked fine for already created accounts, but when I have created a new account the following error was thrown and I was not able to save the account. Please help me.

Error: updateContact: execution of AfterInsert caused by: System.NullPointerException: Attempt to de-reference a null object Trigger.updateContact: line 33, column 1​
 
trigger updateContact on Account (after insert, after update) {
    List<Contact> contactsForUpsert = New List<Contact>();

    Map<Id, Contact> contactsByAccountId = new Map<Id, Contact>();
    List<Contact> contacts = [SELECT Id,
                                     AccountId,
                                     mailingstreet,
                                     mailingcity,
                                     mailingstate,
                                     mailingpostalcode
                            FROM Contact WHERE AccountId IN: Trigger.newMap.keySet()];
    for (Contact cont: contacts) {
        contactsByAccountId.put(cont.accountId, cont);
    }

    for (Account account: Trigger.new) {

        Account old;
        if (Trigger.isUpdate) {
            old = Trigger.oldMap.get(account.Id);
        }

        Boolean isShippingAddressChangedOrNew = Trigger.isInsert ? true :
                                                (   account.ShippingStreet != old.ShippingStreet
                                                 || account.ShippingCity != old.ShippingCity
                                                 || account.ShippingState != old.ShippingState
                                                 || account.ShippingPostalCode != old.ShippingPostalCode
                                                 || account.ShippingCountry != old.ShippingCountry) ? true : false;

        if (isShippingAddressChangedOrNew) {
            Contact relatedContact = contactsByAccountId.get(account.Id);
           
            relatedContact.mailingstreet     = account.Shippingstreet;
            relatedContact.mailingcity       = account.Shippingcity;
            relatedContact.mailingstate      = account.Shippingstate;
            relatedContact.mailingpostalcode = account.shippingpostalcode;
            contactsForUpsert.add(relatedContact);
        

    }

    try {
        upsert contactsForUpsert;
    } catch(Dmlexception e) {
        System.debug(LoggingLevel.ERROR, 'Contact insert from createopp.trigger has failed with message:' + e.getMessage());
    }
}
}

 
  • January 23, 2018
  • Like
  • 0
global class RenewOpportunity implements Database.Batchable<sObject>,Database.stateful{
    string count = '';
    private string query;
     //Start Method....   
    global Database.querylocator start(Database.BatchableContext bc){
        Query = 'SELECT id, name,CloseDate,AccountId,ownerId,Is_Renewed__c'+
            ' FROM Opportunity ' +
            'WHERE CloseDate = NEXT_N_DAYS:30 AND Is_Renewed__c = false';
        return Database.getQueryLocator(query);
    }
    
 //Execute Method...   
    global void execute(Database.BatchableContext bc, List<Opportunity> scope){
    try{
        List<Opportunity> opportunities = new List<Opportunity>();
        List<Opportunity> oppList = (List<Opportunity>)scope ;
        List<Opportunity> opptoUpdate = new List<Opportunity>();
        //count=oppList.size();
        for (Opportunity opp : oppList ) {
            

                 Opportunity renewal = new Opportunity();
                renewal.AccountId   = opp.AccountId;
                renewal.Name        = opp.Name + 'Renewal';
                renewal.CloseDate   = opp.CloseDate + 365;
                renewal.StageName   = 'Open';
                renewal.OwnerId     = opp.OwnerId;
                opportunities.add(renewal);
                
                           
        }
        insert opportunities;
        update opportunities;
        }catch(Exception e){
        count=e.getMessage();
        }
        
    }
//Finish Method....    
    public void finish(Database.BatchableContext bc){
         Id job= bc.getJobId();
        System.debug('Count:'+count);
    }
}

 
  • January 20, 2018
  • Like
  • 0
I'am unable to connect my dev org to trailhead. I got this below error

You are attempting to log into Trailhead to complete challenges with an org that isn't supported.
Please make sure that your Org is
A Developer Edition Org (it cannot be a Production or Sandbox Org) and
The Developer Edition Org does not have a namespace assigned to it.

My dev edition has a namespace assigned but i'm noble to connect it to my trailhead challenges, but i'm able to log on into the workbench using the same username.
  • January 08, 2018
  • Like
  • 0
Hi,

The below trigger was fired after updating the field twice, but it was not fired before update.
 
trigger age on Account (before update) {

  Map<Id,Account> ageMap = new Map<Id,Account>(); 
  Account[] acct = [SELECT Id,Age__c FROM Account WHERE Id IN : Trigger.newMap.keySet()];
    
     for(Account a : trigger.new){
           

            if(a.age__c != null){
             
                ageMap.get(a.Id);
                a.Is_Age_Updated__c = true;
               
            }
            else{
                
             ageMap.get(a.Id);
             a.Is_Age_Updated__c = false;
            }                  
    }

}


 
  • February 02, 2018
  • Like
  • 0
Hi
I have created an apex trigger to update contact address when the account address is changed. The code worked fine for already created accounts, but when I have created a new account the following error was thrown and I was not able to save the account. Please help me.

Error: updateContact: execution of AfterInsert caused by: System.NullPointerException: Attempt to de-reference a null object Trigger.updateContact: line 33, column 1​
 
trigger updateContact on Account (after insert, after update) {
    List<Contact> contactsForUpsert = New List<Contact>();

    Map<Id, Contact> contactsByAccountId = new Map<Id, Contact>();
    List<Contact> contacts = [SELECT Id,
                                     AccountId,
                                     mailingstreet,
                                     mailingcity,
                                     mailingstate,
                                     mailingpostalcode
                            FROM Contact WHERE AccountId IN: Trigger.newMap.keySet()];
    for (Contact cont: contacts) {
        contactsByAccountId.put(cont.accountId, cont);
    }

    for (Account account: Trigger.new) {

        Account old;
        if (Trigger.isUpdate) {
            old = Trigger.oldMap.get(account.Id);
        }

        Boolean isShippingAddressChangedOrNew = Trigger.isInsert ? true :
                                                (   account.ShippingStreet != old.ShippingStreet
                                                 || account.ShippingCity != old.ShippingCity
                                                 || account.ShippingState != old.ShippingState
                                                 || account.ShippingPostalCode != old.ShippingPostalCode
                                                 || account.ShippingCountry != old.ShippingCountry) ? true : false;

        if (isShippingAddressChangedOrNew) {
            Contact relatedContact = contactsByAccountId.get(account.Id);
           
            relatedContact.mailingstreet     = account.Shippingstreet;
            relatedContact.mailingcity       = account.Shippingcity;
            relatedContact.mailingstate      = account.Shippingstate;
            relatedContact.mailingpostalcode = account.shippingpostalcode;
            contactsForUpsert.add(relatedContact);
        

    }

    try {
        upsert contactsForUpsert;
    } catch(Dmlexception e) {
        System.debug(LoggingLevel.ERROR, 'Contact insert from createopp.trigger has failed with message:' + e.getMessage());
    }
}
}

 
  • January 23, 2018
  • Like
  • 0
global class RenewOpportunity implements Database.Batchable<sObject>,Database.stateful{
    string count = '';
    private string query;
     //Start Method....   
    global Database.querylocator start(Database.BatchableContext bc){
        Query = 'SELECT id, name,CloseDate,AccountId,ownerId,Is_Renewed__c'+
            ' FROM Opportunity ' +
            'WHERE CloseDate = NEXT_N_DAYS:30 AND Is_Renewed__c = false';
        return Database.getQueryLocator(query);
    }
    
 //Execute Method...   
    global void execute(Database.BatchableContext bc, List<Opportunity> scope){
    try{
        List<Opportunity> opportunities = new List<Opportunity>();
        List<Opportunity> oppList = (List<Opportunity>)scope ;
        List<Opportunity> opptoUpdate = new List<Opportunity>();
        //count=oppList.size();
        for (Opportunity opp : oppList ) {
            

                 Opportunity renewal = new Opportunity();
                renewal.AccountId   = opp.AccountId;
                renewal.Name        = opp.Name + 'Renewal';
                renewal.CloseDate   = opp.CloseDate + 365;
                renewal.StageName   = 'Open';
                renewal.OwnerId     = opp.OwnerId;
                opportunities.add(renewal);
                
                           
        }
        insert opportunities;
        update opportunities;
        }catch(Exception e){
        count=e.getMessage();
        }
        
    }
//Finish Method....    
    public void finish(Database.BatchableContext bc){
         Id job= bc.getJobId();
        System.debug('Count:'+count);
    }
}

 
  • January 20, 2018
  • Like
  • 0
I'am unable to connect my dev org to trailhead. I got this below error

You are attempting to log into Trailhead to complete challenges with an org that isn't supported.
Please make sure that your Org is
A Developer Edition Org (it cannot be a Production or Sandbox Org) and
The Developer Edition Org does not have a namespace assigned to it.

My dev edition has a namespace assigned but i'm noble to connect it to my trailhead challenges, but i'm able to log on into the workbench using the same username.
  • January 08, 2018
  • Like
  • 0