• chandan kumar 99
  • NEWBIE
  • 20 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 4
    Replies
Hello Gurus:-
We have standard "Contact" object in SFDC.
and field is Total_Family_Member__c (number field )on the contact
object
my scenario is when contact is created in the same accountId then contact field (Total_Family_Member__c) is the update. 
my code
is :--
trigger Totalfamilymember2 on Contact (Before insert,Before update,Before delete,Before Undelete) {
   
set<id> ids = new set<id>();
    list<contact> contactToUpdate = new List<contact>();
    if(Trigger.isinsert||Trigger.isupdate|| Trigger.isundelete){
        for(contact con : trigger.new){
            if(con.AccountId != null){
               Ids.add(con.AccountId);
           }
        }
    }
    
    if(Trigger.isdelete){
        for(contact con : trigger.old){
            if(con.AccountId != null){
               Ids.add(con.AccountId);
           }
        }
    }
    
     for(AggregateResult ar :[SELECT AccountId,count(id) related FROM Contact  where AccountId in: Ids  GROUP BY AccountId]){
                    
                 contactToUpdate.add(new contact(Accountid = (Id)ar.get('AccountId'),Total_Family_Member__c= (Decimal)ar.get('related') ));
           }
                
               
    
}

Result is not show please find ???
my code is :-
public class AccountDetailCtr{ 
public Account account{get; set;}
   public List<Account> getlstAcc(){
        List<Account> accounts = new List<Account>();
         accounts=[Select id,name,AnnualRevenue,rating,Industry,Phone,ShippingAddress,AccountNumber from account ];
                     
            if(accounts!=null && accounts.size()>0)
                return accounts ;
            
            else
                ApexPages.addMessage(new ApexPages.Message(ApexPages.severity.info,'No account record found'));    
        return accounts ;
    }
    
    public PageReference save() {
        update account;
         pagereference p = page.SecondPageSLDS;
                             p.setRedirect(true);
                             p.getParameters().put('id', account.Id);
                             return p;
    }    
}
when save button press then following error show

Attempt to de-reference a null object
Error is in expression '{!save}' in component <apex:commandButton> in page secondpageslds: Class.AccountDetailCtr.save: line 16, column 1
An unexpected error has occurred. Your development organization has been notified.
Hello Gurus,
I have a create Account List page And create a button(New Account) in list page when clicking a new account button go to Account new page  
My SLDS Button Code is:=
        <div class="slds-col slds-no-flex slds-grid slds-align-top slds-button-group" role="group">
          <button class="slds-button slds-button--neutral">New Account</button> 
        </div>
Thanks 
 
Hi Gurus, 

I have a trigger on Task object and I am trying to before insert and update a field Task object. I am getting following error message:
Error: Invalid Data. 
Review all error messages below to correct your data.
Apex trigger WeekendTasks caused an unexpected exception, contact your administrator: WeekendTasks: execution of BeforeUpdate caused by: System.DmlException: Update failed. First exception on row 0 with id 00T7F00000G5ulOUAR; first error: SELF_REFERENCE_FROM_TRIGGER, Object (id = 00T7F00000G5ulO) is currently in trigger WeekendTasks, therefore it cannot recursively update itself: []: Trigger.WeekendTasks: line 15, column 1

Here is my trigger
trigger WeekendTasks  on Task (before insert,Before update) {
    list<Task> Tasweek =new List<Task>();
           for(Task tweek:Trigger.new){
                if(tweek.Subject != null) {
                   Date origin = Date.newInstance(1900,1,6);
                   Date due = tweek.ActivityDate;
                   Integer x = origin.daysBetween(due);
                   Integer day = Math.mod(x,7);
                   if (day < 2 ) {
                     Task tas = new Task (Id = tweek.Id,ActivityDate = (tweek.ActivityDate + 2));
                     Tasweek.add(tas);
                   }
                 }
           }
          update Tasweek;  
}
Hi everyone 
my question is 

How Many way to create multi-select picklist. Please solve


Thanks
Hi Gurus, 

I have a trigger on Task object and I am trying to before insert and update a field Task object. I am getting following error message:
Error: Invalid Data. 
Review all error messages below to correct your data.
Apex trigger WeekendTasks caused an unexpected exception, contact your administrator: WeekendTasks: execution of BeforeUpdate caused by: System.DmlException: Update failed. First exception on row 0 with id 00T7F00000G5ulOUAR; first error: SELF_REFERENCE_FROM_TRIGGER, Object (id = 00T7F00000G5ulO) is currently in trigger WeekendTasks, therefore it cannot recursively update itself: []: Trigger.WeekendTasks: line 15, column 1

Here is my trigger
trigger WeekendTasks  on Task (before insert,Before update) {
    list<Task> Tasweek =new List<Task>();
           for(Task tweek:Trigger.new){
                if(tweek.Subject != null) {
                   Date origin = Date.newInstance(1900,1,6);
                   Date due = tweek.ActivityDate;
                   Integer x = origin.daysBetween(due);
                   Integer day = Math.mod(x,7);
                   if (day < 2 ) {
                     Task tas = new Task (Id = tweek.Id,ActivityDate = (tweek.ActivityDate + 2));
                     Tasweek.add(tas);
                   }
                 }
           }
          update Tasweek;  
}
Hi everyone 
my question is 

How Many way to create multi-select picklist. Please solve


Thanks
  • We have standard "Contact" object in SFDC.
  • You have to add one Field in Contact Object that is "Total Family Members" type is Number(2,0):
  • Let Account be the Family. So if there are 5 Contacts belongs to same account, that means these all 5 belongs to same family.
What you have to do:                 
  • Create a trigger on Contact to calculate "Family Members Count".
    • Create one Account: Create New Contact as a child for it. Then Contact's "Total Family Member" will have value 1.
    • Create another Contact for the same Account then Both Contact should have value 2 for "Total Family Member Field".
    • if someone changes contact's family like : changing account lookup value for a contact, then Both family will reflect. Because one family member is removed from one family and added to new Family. values should be updated: 
      •  All Contact's of Older Family should now have the "Total Family Member" value decreased by1. 
      • And for new family all Contact's "Total Family Member" will have value increased by1.