• Abdul Khatri
  • PRO
  • 2615 Points
  • Member since 2015

  • Chatter
    Feed
  • 86
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 844
    Replies
I'm trying to pull a few fields into an IF formula and I'm not receiving a syntax error but the formula isn't calculating.  What am I missing?

Monthly Revenue at End of Contract
IF(((Contract_Term_Yrs__c * 12) < Months_to_sign_existing_clients__c),((Contract_Term_Yrs__c * 12) * New_Monthly_Revenue_Existing__c),(Months_to_sign_existing_clients__c * New_Monthly_Revenue_Existing__c))
Contract_Term_Yrs__c =  Number Field
Months_to_sign_existing_clients__c = Formula Field(Number)
New_Monthly_Revenue_Existing__c = Formula Field(Currency) 



 
the trigger should be on account to check the assets and if ALL Assets where product family = "bla bla "  and their status was "Canceled" the trigger should update bla bla Account stage (API Name = Account_Status__c )  to "Cancel".
trigger populate on project__c (before insert , before update){
 
    
    
     MAP<ID , user> mapCon = new MAP<ID , user>([Select id ,name,city
                                                 from user 
]);
     for(project__c  obj : trigger.new)
       {
        if(obj.delivery_location__c == null)
          {
           user u  = mapcon.get(obj.ownerid);
              if (u.city != null)
              
             obj.Delivery_location__c=u.city;
              else {
                   obj.Delivery_location__c = 'NA';
              }
          }
       
       }
       
       }
When I run this 

List<ObjectPermissions> objPermList = new List<ObjectPermissions>();
List<FieldPermissions> fieldPermList = new List<FieldPermissions>();
//get the object permisisons for a given profile – source
List<ObjectPermissions> objPermissionList = [SELECT Id, SobjectType, PermissionsCreate, PermissionsRead, PermissionsEdit, PermissionsDelete,
PermissionsModifyAllRecords,PermissionsViewAllRecords FROM ObjectPermissions
where ParentId in (select id from PermissionSet where profile.name = ‘System Administrator’)];
//get the field permissions for a given profile – source
List<FieldPermissions> fldPermissionList = [SELECT Id, ParentId, SobjectType, Field, PermissionsEdit, PermissionsRead FROM FieldPermissions
where ParentId in(select id from PermissionSet where profile.name = ‘System Administrator’)];
//destination permisison set
List<PermissionSet> permissionSetList = [select id from PermissionSet where name = ‘System_Administrator’];
PermissionSet permissionSet = permissionSetList.get(0);
//set object permissions
for(ObjectPermissions oP : objPermissionList)
{
ObjectPermissions objPerm = new ObjectPermissions();
objPerm.ParentId = permissionSet.id;
objPerm.SobjectType = oP.SobjectType;
objPerm.PermissionsCreate = true;
objPerm.PermissionsDelete = true;
objPerm.PermissionsEdit = true;
objPerm.PermissionsModifyAllRecords = true;
objPerm.PermissionsRead = true;
objPerm.PermissionsViewAllRecords = true;
objPermList.add(objPerm);
}
Database.upsert(objPermList, false);
//set field permissions
for(FieldPermissions fp : fldPermissionList)
{
FieldPermissions fldPerm = new FieldPermissions();
fldPerm.ParentId = permissionSet.id;
fldPerm.SobjectType = fp.SobjectType;
fldPerm.Field = fp.Field;
fldPerm.PermissionsEdit = true;
fldPerm.PermissionsRead = true;
fieldPermList.add(fldPerm);
}
Database.upsert(fieldPermList, false);

I get the following error message
Line: 7, Column: 70
Invalid identifier '‘System'. Apex identifiers must start with an ASCII letter (a-z or A-Z) followed by any number of ASCII letters (a-z or A-Z), digits (0 - 9), '$', '_'.

What could be wrong in this 
Hi ,
I have created a trigger on Task that updates last activity date whenever a task is created on a Lead / contact / Opp. 

The trigger works fine when I create a single task or recurrence when the recurrence date is only for one day(Recurrence Start & Recurrence End are on same day). But when the recurrence is created for two or more days (Recurrence Start & Recurrence End are on different days Ex: Start = 01/01/2019 & End=01/02/2019) then it is throwing an error.  

Here is the error message

Error: Invalid Data. 
Review all error messages below to correct your data.
Apex trigger UpdateLastActivityDate caused an unexpected exception, contact your administrator: UpdateLastActivityDate: execution of AfterInsert caused by: System.ListException: Duplicate id in list: 003c000001G7hkTAAR: Trigger.UpdateLastActivityDate: line 37, column 1

Here is the Trigger Code along with lines mentioned error in bold
trigger UpdateLastActivityDate on Task (after insert) {

    //updating Last_sales_activity__c on lead, contact and opportunity for new activities
    
     if( trigger.isAfter && trigger.isInsert  )
    {
        List<Contact> lstContactsToUpdate=new List<contact>();
        List<Lead> lstLeadsToUpdate=new List<Lead>();
        List<Opportunity> lstOpportunitiesToUpdate=new List<Opportunity>();
        
        Profile p = [ Select Id, Name from Profile where Id =: UserInfo.getProfileId() ];
        if( p.Name.equalsIgnoreCase( 'Standard Sales User' ) )
        {    
            for( Task t : trigger.new )
        {    system.debug('t whatId..'+t.WhatId);
             system.debug('t whoId..'+t.WhoId);
              if( t.WhoId != null && String.valueOf( t.WhoId ).startsWith( '003' ))//003 =contact
                {
                    contact c=new contact(Id=t.WhoId);
                    c.Last_sales_activity__c=system.today();
                    lstContactsToUpdate.add(c);
                }else if( t.WhatId != null && String.valueOf( t.WhatId ).startsWith( '006' ))//006 =opportunity
                {system.debug('t----006---');
                    Opportunity c=new Opportunity(Id=t.WhatId);
                    c.Last_sales_activity__c=system.today();
                    lstOpportunitiesToUpdate.add(c);
                }else if( t.WhoId != null && String.valueOf( t.WhoId ).startsWith( '00Q' ))//00Q =Lead
                {
                    Lead c=new Lead(Id=t.WhoId);
                    c.Last_sales_activity__c=system.today();
                    lstLeadsToUpdate.add(c); 
                }
            
            
        }
            if(lstContactsToUpdate.size()>0){
                update lstContactsToUpdate;
            }
            if(lstOpportunitiesToUpdate.size()>0){
                update lstOpportunitiesToUpdate;
            }
            if(lstLeadsToUpdate.size()>0){
                update lstLeadsToUpdate;
            }
            
        }
        
   }

 }

I could not figure what I am missing here.

Let me know what changes I need to do to overcome this error.

Thanks
Rao
  • January 10, 2019
  • Like
  • 0

Hello,
I'm an admin that has just written my first integration. The code makes a call to an external service, receives some json, and then parses it and places it into a custom object. The json could either contain new records or update an existing record from a previous run...this is being done with upsert dml statement.  This process runs on a schedule. 

My question is regarding testing. There are no problems with testing the insert of new records. There is a test method that sets up all of the needed test data and a json string that makes use of that test data. The method returns that string and is used as a mockHTTPResponse. This tests everything except for the branch of code that updates existing records. This is where I'm challenged...I don't see how I can make another json string that uses first set of test data. 

So, I'm hoping that someone out there has been through this before and can offers some suggestions. 

Hello friends, I want to add Multiple email address for sending the email in To: input box, but it doesnot accept more than one. Do anyone know how to solve this.
Please find the code below

public class sendemailtestcontroller {

    public sendemailtestcontroller() {

    }





    public String toEmail {get;set;}
    public String subject {get;set;}
    public String body {get;set;}
    
    
    private final Lead MyLead;
    public sendemailtestcontroller(ApexPages.StandardController controller)
    
   
    {
        this.MyLead=(Lead)controller.getRecord();
    } 
   
             
    public void sendEmail() {
        
        //create a mail object to send email 
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        
        String[] toaddress = (new String[]{toEmail});
        
        //email properties
        mail.setToAddresses(toaddress);
        mail.setSubject(subject);
        mail.setUseSignature(true);
        mail.setPlainTextBody(body); 
               
        // send the email
        Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
     }   
   

}

Vf :
<apex:page standardcontroller="Lead" extensions="sendemailtestcontroller">
  <apex:pageBlock title="EMAIL TEST">
        <apex:form >
        <br />
            <apex:outputLabel value="To" for="To"/>:<br/>
            <apex:inputText value="{!toEmail}" id="email"/><br/><br/>
                        
            <apex:outputLabel value="Subject" for="Subject"/>:<br />     
            <apex:inputTextarea value="{!subject}" id="Subject" cols="80" /><br/><br/>
                        
            <apex:outputLabel value="Body" for="Body"/>:<br />     
            <apex:inputTextarea value="{!body}" id="Body" rows="10" cols="80"/><br/><br/>      
            <br /><br />
                        
            <apex:commandButton value="Send Email" action="{!sendEmail}"  />
            <apex:commandButton value="Cancel" action="{!cancel}"/> 
        
        </apex:form>
    </apex:pageBlock>
</apex:page>

User-added image
Hi

I have a scenario where the account currency and opportunity currency can be different. The opportunity currency should be the same as opportunity owner currency. I have to write a trigger for it. Can anyone help me with it.
Highly appreciated.
Hello!
I'm stuck on challenge 9 of this superbadge and would appreciate some help please. I have everything set up as asked in the challenge and have cross verified several posts to make sure everything is right (including my page layout). But I keep getting the error below. Please help! Thank you in advance.

Error
Invoices
Hello,

I am learning Salesforce integration and wanted to know if it's possible to have SOAP or HTTP Callout from a standard page/button?  Per documentation, it mentioned it can be triggered from the Visualforce/button but not sure if it's possible from a standard page?  Thanks in advance!

 
Hi All,
I have a requirement to display a list of licenses associated to customer account on a case object. How will I achieve that ? here is the detail

I have deployed_licenses__c custom object that is in parent-child relation to Account object (a customer may have different kinds of licenses with different version). Our support would like to see the list of licenses that customer account have on the case page as a related list. They do not want to go to Account page to see the liocenses. Account is a lookup field on the case object. 
Thank You
YM

 
Hi Friends, 

I know null pointer errors are such a common question I hate to add another one. But I can't figure out what I am doing wrong and I am hoping I can learn something here.  I'm getting the error from my final For Loop. I thought I had checked for it with the != null in my If statement. Hoping someone can point me in the right direction.
 
public  class UniqueEmailCountHandler {
    
    public static void uniqueRelationshipOwnerEmails(List<relationship_owner__c> roList){
        //count the unique emails  that have been sent by a relationship owner
        // add all contacts associated with relationship owner to map.         
        Map<id, Contact> contactMap = new Map<Id, Contact>([SELECT Id,
                                                            New_Relationship_Owner1__c
                                                            FROM Contact
                                                            WHERE New_Relationship_owner1__c IN : roList]);
        system.debug('Number of relationship owners in trigger = ' + roList.size());
        system.debug('Contacts found = ' + contactMap.size());
        //put tasks where whoId is in the contact map into a new map
        List<Task> taskList = [SELECT Id, WhoId,Subject
                               FROM Task 
                               WHERE WhoId IN :contactMap.keySet()
                               AND Subject LIKE '%Pardot List %'];
        system.debug('Tasks Found  and added to map = ' + taskList.size());
        
        //use set to dedupe the list
        Map<Id, Set<String>> subjectLineMap = new Map<Id, Set<String>>();
        
        for(task t : taskList){
            Id ownerId = contactMap.get(t.WhoId).New_Relationship_Owner1__c;            
            if(!subjectLineMap.containsKey(ownerId)){
                subjectLineMap.put(ownerId, new Set<String>());
                system.debug('Subect Line found ' + t.Subject);              
                
            }
            Set<String> subjects = subjectLineMap.get(OwnerId);
            subjects.add(t.Subject);
            subjectLineMap.put(OwnerId, Subjects);
            
        }
        system.debug('Map size   =' + subjectLineMap.size());
        system.debug('map values =' + subjectLineMap.values());
        system.debug('map keys   =' + subjectLineMap.Keyset());
        {
            for(relationship_owner__c relationshipOwner : roList){
                if(subjectLIneMap.get(relationshipOwner.Id).size() != Null){
                relationshipOwner.Unique_Emails_Sent__c = subjectLIneMap.get(relationshipOwner.Id).size();
                }
                
            }

 
Hi All, Please help!

I have the following scenario of at least four email address field on one object called Students
  1. Email1
  2. Email2
  3. Email3
  4. Email4
All with a LastModified date that captures the date on update of that particular email address. Please note the fields are named after the parent email address.On the following fields:
  1. Email1Date
  2. Email2Date
  3. Email3Date
  4. Email4Date
Formula fields to caculate the number of days the email was modified or created from today.Please note days are name after the parent date
  1. Email1Days
  2. Email2Days
  3. Email3Days
  4. Email4Days
A primary email address field:
  1. PrimaryEmail

The objective is to create a trigger that will loop through the number of days and find the lowest and then populate the Primary email address with a corresponding address. This  lowest number of days will mean the email is current therefore populate the primary address. However  the logic  should  also be able to  take into consideration when one or more number of days fields are blank. Please note they is always one or more addresses all the time. The logic should also exempt users who manually update the Primary email address field.

Many Thanks 


 
I need help writing a trigger to prevent Obj1 records from being cancelled (Status__c = "Cancelled") or completed (Status__c = "Completed") if there are open activities/tasks that are not completed or cancelled, or if related records from Obj2 or Obj3 are still open. Obj1 may have mutiple related records from Obj2 and Obj3. The look-up field on Obj2 and Obj3 is called 'Obj1__c'.
I'm trying to create a validation rule on the contact that checks to see if:

1: there is a task associated with that contact
2: if the subject line of the task matches a given string.

However, I just can't figure out what field to use in the formula editor for the validation rule. Is this even possible?

Thank you in advance for any replies or advice!
This is what my code is suppose to be doing: 
To pass this challenge, create an Apex class that inserts a new account named after an incoming parameter. If the account is successfully inserted, the method should return the account record. If a DML exception occurs, the method should return null.


public class AccountHandler {

    public static Account insertNewAccount(String accName){
        if(accName!=''){    
            try{
                Account a = new Account(Name=accName);
                insert a;    
                return a;
            } catch(Exception e){
                
                return null;
            }
        } else {
        return null;
        }
    }
}

When I test it inside of the execute anonymous window, I input "insertNewAccount('abcd');". I get an error saying "Method does not exist or incorrect signature: void insertNewAccount(String) from the type anon"
 
INVALID_CROSS_REFERENCE_KEY: Record Type ID: this ID value isn't valid for the user: 0121h0000000AwKAAU

I have permission to this record type on both my profile as well as in a permission set. 

I'm able to create records of this type manually, however when I attempt to trigger the flow, the error occurs.

Thanks for your help!
We would like to use our first Process Builder to automatically complete certain fields to save the user's time as well as get better accuracy in NPSP SF for creating a new Opportunity and based on an Opportunity Type. We have Member Levels based on the Payment Amount to automatically record into a Member Level field.  I have used Help trying to find the right formula in Process Builder to do this but get an error when it finds <. 

One help topic suggested I may not be able to do this in Process Builder but here is my logic I've developed. I also assumed that going through each step would return the right Member Level without having to do a range of >=  &&  <. on each Member Level picklist value.

IF([Opportunity].npe01__Payments_Made__c >= 35, [Opportunity].npe01__Member_Level__c = "Individual", 
    IF([Opportunity].npe01__Payments_Made__c >= 60, 
    [Opportunity].npe01__Member_Level__c ="Family",
       IF([Opportunity].npe01__Payments_Made__c >= 100, 
       [Opportunity].npe01__Member_Level__c ="Supporter",
           IF([Opportunity].npe01__Payments_Made__c >= 150, 
           [Opportunity].npe01__Member_Level__c ="Sustainer",
               IF([Opportunity].npe01__Payments_Made__c >= 300, 
               [Opportunity].npe01__Member_Level__c ="Patron",
                  IF([Opportunity].npe01__Payments_Made__c >= 500, 
                  [Opportunity].npe01__Member_Level__c ="Benefactor",
                     IF([Opportunity].npe01__Payments_Made__c >= 5000, 
                     [Opportunity].npe01__Member_Level__c =" Lifetime $5000",
null)) ) ) ) ) ) 
This has happened on several occasions in the past and it's happening again today.

I created a fairly simple 'before insert' trigger for opportunity products. When I test the trigger under the administrator account, with the developer console on, the code runs perfectly as intended. But when I close the developer console window, the trigger no longer fires.

The same thing happens for different users as well. If I set a trace flag for a particular user, the trigger fires just fine when logged in as that user. But after deleting the trace flag, the trigger stops firing. I can duplicate this behavior back and forth over and over.

If anyone could point me in the right direction, I would really appreciate it. Right now it's a struggle finding any relevant info.

Note sure if this will help but here's the code for the trigger:
trigger OpportunityProductInsert on OpportunityLineItem (before insert)
{
    // List of all line items IDs before being inserted
    List<Id> oliIds = new List<Id>();
    
    // List of all opportunity IDs of the line items
    List<Id> oliOppIds = new List<Id>();
    
    // List of all product IDs associated to the line items
    List<Id> oliProductIds = new List<Id>();
    
    for ( OpportunityLineItem newOli : trigger.new )
    {
        oliIds.add(newOli.Id);
        oliOppIds.add(newOli.OpportunityId);
        oliProductIds.add(newOli.Product2Id);
    }

    // Map to retrieve the account ID for each opportunity
    Map<Id, Id> oliAccountIdMap = new Map<Id, Id>();    
    List<Opportunity> opps = [SELECT Id, AccountId FROM Opportunity WHERE Id IN: oliOppIds];
    for ( Opportunity opp : opps )
    {
        oliAccountIdMap.put(opp.Id, opp.AccountId);
    }
    
    // List of all product IDs that are inventory items
    List<Id> inventoryProductIds = new List<Id>();    
    List<Product2> products = [SELECT Id FROM Product2 WHERE IsNonInventory__c = false AND Id IN: oliProductIds];
    for ( Product2 product : products )
    {
        inventoryProductIds.add(product.Id);
    }
    
    // Map to retrieve a list of available products for each account
    Map<Id, List<Id>> accProductMap = new Map<Id, List<Id>>();
    List<Id> accProductIds;
    List<AccountProduct__c> accProducts = [SELECT Account__c, Product__c FROM AccountProduct__c WHERE Account__c IN: oliAccountIdMap.values()];
    for ( AccountProduct__c accProduct : accProducts )
    {
        accProductIds = new List<Id>();
        if ( accProductMap.containsKey(accProduct.Account__c) )
        {
            accProductIds = accProductMap.get(accProduct.Account__c);
        }
        accProductIds.add(accProduct.Product__c);
        accProductMap.put(accProduct.Account__c, accProductIds);
    }
    
    // Check that the product is available on the account
    for ( OpportunityLineItem checkOli : trigger.new )
    {
        accProductIds = new List<Id>();        
        Id accId;
        
        // Retrieve the account ID from the line item ID        
        if ( oliAccountIdMap.containsKey(checkOli.OpportunityId) )
        {
            accId = oliAccountIdMap.get(checkOli.OpportunityId);            
        }    
            
        if ( accId != null )
        {
            // If the product ID on the line item is in the list of inventory items
            if ( inventoryProductIds.contains(checkOli.Product2Id) )
            {                
                accProductIds = new List<Id>();
                
                // Retrieve list of available products on the account
                if ( accProductMap.containsKey(accId) )
                {
                    accProductIds = accProductMap.get(accId);         
                }
                
                // If the product ID is not in the list of account product IDs            
                if ( !accProductIds.contains(checkOli.Product2Id) )
                {
                    checkOli.addError('This product isn\'t available for this account.');
                }                                    
            }
        }
    }
}
  • September 04, 2018
  • Like
  • 0
Can any one help in this? I am new in Trigger. and need a code that cover all the conditions.
System.debug the following statements for any object a)Trigger.New b) Trigger.Old c)Trigger.NewMap d)Trigger.oldMap
  • July 21, 2018
  • Like
  • 0
Hi,

I am looking to see the best approach for Salesforce CI. I have gone through many forum and blogs but haven't been able to grasp them. I tried to setup CI for the entire org but facing a lot of challeges which I guess you guys quite aware of.

What I am looking to do incremental deployment based on the git diff, dynamically generate package.xml based on the metadata committed which I think would be manageable something like sfdc-git-package https://www.npmjs.com/package/sfdc-git-package. I am having a hard time implementing this.

Please someone help
Can someone help me to show how I can change the Sales Console Lightning Layout. Currently it is showing as shown in the screen shot below as 3 Column layout. I wanted to change the layout to show the highlight panel on top. I am finding no help from Salesforce help section or trailhead for this. Please bear in mind I am talking about Lightning Sales Console and not Classic. I did the Edit Page and takes me but doesn't allow me to change the layout. 

User-added image
Is there a way to hide "Save & New" Button from the Task page Layout?

User-added image

I looked at everywhere and couldn't find the solution. I do want to give them Create/Edit Permission so no option there to remove that.

Please help
Custom URL for the cast creating inline headers and side bar. I tried the following addition things

            urlConcat += '&inline=0';
            urlConcat += '&isdtp=lt';
            urlConcat += '&isdtp=nv';
            urlConcat += '&isdtp=vw';

the only one that work is '&isdtp=nv' but after saving the activity, the hyperlink in the related list doesn't work. I have attached a screen shot 

User-added image

Anyone can help?

 
Hi,

I am looking to see the best approach for Salesforce CI. I have gone through many forum and blogs but haven't been able to grasp them. I tried to setup CI for the entire org but facing a lot of challeges which I guess you guys quite aware of.

What I am looking to do incremental deployment based on the git diff, dynamically generate package.xml based on the metadata committed which I think would be manageable something like sfdc-git-package https://www.npmjs.com/package/sfdc-git-package. I am having a hard time implementing this.

Please someone help
I'm trying to pull a few fields into an IF formula and I'm not receiving a syntax error but the formula isn't calculating.  What am I missing?

Monthly Revenue at End of Contract
IF(((Contract_Term_Yrs__c * 12) < Months_to_sign_existing_clients__c),((Contract_Term_Yrs__c * 12) * New_Monthly_Revenue_Existing__c),(Months_to_sign_existing_clients__c * New_Monthly_Revenue_Existing__c))
Contract_Term_Yrs__c =  Number Field
Months_to_sign_existing_clients__c = Formula Field(Number)
New_Monthly_Revenue_Existing__c = Formula Field(Currency) 



 
the trigger should be on account on update, to check the assets and if all Assets belonging to product family = "bla bla "  have their status "Canceled" the trigger should update bla bla Account stage (API Name = Account_Status__c )  to "Cancel". 
I'm currently working on a sandbox record creation class so I can prepopulate a couple records when refreshing sandboxes. However, I'm very inexperienced with Apex code and am hitting query limits, most likely because I'm having to look up the records previously created in the class. Is there a way that I can set the newly created record in the class so that I can then use the record ID as a variable in later methods? Basically all the queries here should be variables.
Here's the class:
public class SandboxClass {
    // Use this method to insert the accounts, the contacts, and the donations
    // you will need one method per object here is the account method
    public Account InsertCouplesAccount(){
        Account Acct1 = new Account();
        Acct1.Name='Couples Household';
        Acct1.Type='Household';
        Acct1.Location__c='City';
        Acct1.BillingCity ='City';
        Acct1.BillingCountry='United States';
        Acct1.BillingStreet='123 Test St.';
        Acct1.BillingState='Illinois';
        Acct1.BillingPostalCode='12345';   
        
        
        insert Acct1;
        return Acct1;
    } 
    public  Account InsertSingleAccount() {
    	Account Acct2 = new Account();
        Acct2.Name='Single Household';
        Acct2.Type='Household';
        Acct2.Location__c='Town';
        Acct2.BillingCity ='Indescript City';
        Acct2.BillingCountry='United States';
        Acct2.BillingStreet='321 Testing St.';
        Acct2.BillingState='Illinois';
        Acct2.BillingPostalCode='54321';
        
        insert Acct2;
        return Acct2;
    } 
    public Contact InsertHusbandContact() {
        Account Acct = [SELECT Id FROM Account WHERE Name = 'Couples Household'];
        Contact HusbCon = new Contact();
        HusbCon.Salutation = 'Mr.';
        HusbCon.FirstName = 'John';
        HusbCon.LastName = 'Couples';
        HusbCon.AccountId = Acct.Id;
        
        insert HusbCon;
        return HusbCon;
    }
    public Contact InsertWifeContact() {
        Account Acct = [SELECT Id FROM Account WHERE Name = 'Couples Household'];
        Contact HusbCon = [SELECT Id FROM Contact WHERE LastName = 'Couples'];
        Contact WifeCon = new Contact();
        WifeCon.Salutation = 'Mrs.';
        WifeCon.FirstName = 'Jane';
        WifeCon.LastName = 'Couples';
        WifeCon.AccountId = Acct.Id;
        WifeCon.Spouse__c = HusbCon.Id;
        
        insert WifeCon;
        return WifeCon;
    }
    public Contact UpdateHusbandContact() {
        Contact HusbCon = [SELECT Id FROM Contact WHERE FirstName = 'John'];
        Contact WifeCon = [SELECT Id FROM Contact WHERE FirstName = 'Jane'];
        HusbCon.Spouse__c = WifeCon.Id;
        
        update HusbCon;
        return HusbCon;
    }
    public Contact InsertSingleContact() {
        Account Acct = [SELECT Id FROM Account WHERE Name = 'Single Household'];
        Contact SingCon = new Contact();
        SingCon.Salutation = 'Mr.';
        SingCon.FirstName = 'Jack';
        SingCon.LastName = 'Single';
        SingCon.AccountId = Acct.Id;
        
        insert SingCon;
        return SingCon;
    }
    public Opportunity InsertCoupleDonation1() {
        Account Acct = [SELECT Id FROM Account WHERE Name = 'Couples Household'];
        Contact Cont = [SELECT Id FROM Contact WHERE FirstName = 'John'];
        Opportunity Don1 = new Opportunity();
        Don1.AccountId = Acct.Id;
        Don1.Contact__c = Cont.Id;
        Don1.StageName = 'Posted';
        Don1.Name = 'Couple Donation 1';
        Don1.Amount = 15;
        Don1.CloseDate = System.today();
        Don1.Location__c = 'City';
        Don1.Method_of_Payment__c = 'Cash';
        Don1.RecordTypeId ='0121N000000uGN8QAM';

        
        insert Don1;
        return Don1;
    }
    public Opportunity InsertCoupleDonation2() {
        Account Acct = [SELECT Id FROM Account WHERE Name = 'Couples Household'];
        Contact Cont = [SELECT Id FROM Contact WHERE FirstName = 'Jane'];
        Opportunity Don2 = new Opportunity();
        Don2.AccountId = Acct.Id;
        Don2.Contact__c = Cont.Id;
        Don2.StageName = 'Posted';
        Don2.Name = 'Couple Donation 2';
        Don2.Amount = 20;
        Don2.CloseDate = System.today();
        Don2.Location__c = 'Town';
        Don2.Method_of_Payment__c = 'Credit Card';
        Don2.RecordTypeId ='0121N000000uGN8QAM';

        
        insert Don2;
        return Don2;
    }
    public Opportunity InsertSingleDonation1() {
        Account Acct = [SELECT Id FROM Account WHERE Name = 'Single Household'];
        Contact Cont = [SELECT Id FROM Contact WHERE FirstName = 'Jack'];
        Opportunity Don3 = new Opportunity();
        Don3.AccountId = Acct.Id;
        Don3.Contact__c = Cont.Id;
        Don3.StageName = 'Posted';
        Don3.Name = 'Single Donation 1';
        Don3.Amount = 10;
        Don3.CloseDate = System.today();
        Don3.Location__c = 'City';
        Don3.Method_of_Payment__c = 'Cash';
        Don3.RecordTypeId ='0121N000000uGN8QAM';

        
        insert Don3;
        return Don3;
    }
    public Opportunity InsertSingleDonation2() {
        Account Acct = [SELECT Id FROM Account WHERE Name = 'Single Household'];
        Contact Cont = [SELECT Id FROM Contact WHERE FirstName = 'Jack'];
        Opportunity Don4 = new Opportunity();
        Don4.AccountId = Acct.Id;
        Don4.Contact__c = Cont.Id;
        Don4.StageName = 'Posted';
        Don4.Name = 'Single Donation 2';
        Don4.Amount = 25;
        Don4.CloseDate = System.today();
        Don4.Location__c = 'Town';
        Don4.Method_of_Payment__c = 'Cash';
        Don4.RecordTypeId ='0121N000000uGN8QAM';

        
        insert Don4;
        return Don4;
    }
    public Opportunity InsertSingleDonation3() {
        Account Acct = [SELECT Id FROM Account WHERE Name = 'Single Household'];
        Contact Cont = [SELECT Id FROM Contact WHERE FirstName = 'Jack'];
        Opportunity Don5 = new Opportunity();
        Don5.AccountId = Acct.Id;
        Don5.Contact__c = Cont.Id;
        Don5.StageName = 'Posted';
        Don5.Name = 'Single Donation 3';
        Don5.Amount = 45;
        Don5.CloseDate = System.today();
        Don5.Location__c = 'Town';
        Don5.Method_of_Payment__c = 'Cash';
        Don5.RecordTypeId ='0121N000000uGN8QAM';

        
        insert Don5;
        return Don5;
    }
}

 
the trigger should be on account to check the assets and if ALL Assets where product family = "bla bla "  and their status was "Canceled" the trigger should update bla bla Account stage (API Name = Account_Status__c )  to "Cancel".
Hello
I have requirement to calculate today hours for the current week. 
We have custom object Tracker__C and field Hours__C. Hours__C is user entered field. Next to the user entered field we wanted to show the users total hours he has entered thus far this week. 
For example  (Day of the week - Hours entered - Total hours this week)
Monday - 4 - 4
Tuesday - 6 - 10
Wednesday - 2 - 12
Thursday - 8 - 20
Friday - 8 - 28

All help appreciated
Thanks
Dinesh
  • January 14, 2019
  • Like
  • 0

trigger AccEmail on Contact (after insert,after update) {
    String Em='';
    if(trigger.isInsert || trigger.isUpdate ){
    Set <String> accID = New Set <String> ();
    For (Contact con: Trigger.new) {
        if (con.AccountId != Null ) {
        accID.add (con.AccountId);
        }
    }
   
    if (accID.size ()> 0) {
        List <Account> upAccList = new List <Account> ();
       
      for(Account acc : [Select id, EmailId__c,
                             (Select Id, Email From Contacts)
                        From Account Where Id In : accID])
  
       for(Contact con : acc.contacts)
       {
        if(con.Email != null)
        {
            Em = Em + ', ' + con.Email;
        }
        acc.Contact_Names__c = names;
       
     upAccList.add(acc);
   }   
   update upAccList;
}
    }