• Mubeen Qawi
  • NEWBIE
  • 35 Points
  • Member since 2014

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 21
    Replies
I am New to apex development:

this is my trigger:

trigger ContactTrigger on Contact(after delete, after insert, after undelete, after update, before delete, before insert, before update) {

  ContactTriggerHandler handler = new ContactTriggerHandler();

  /* Before Insert */
  if(Trigger.isInsert && Trigger.isBefore){
   // handler.OnBeforeInsert(Trigger.new);
  }
  
  /* After Insert */
  else if(Trigger.isInsert && Trigger.isAfter){
    handler.OnAfterInsert(Trigger.new);
  }
  
  /* Before Update */
  else if(Trigger.isUpdate && Trigger.isBefore){
    //handler.OnBeforeUpdate(Trigger.old, Trigger.new, Trigger.newMap, Trigger.oldMap);
  }
  
  /* After Update */
  else if(Trigger.isUpdate && Trigger.isAfter){
   // handler.OnAfterUpdate(Trigger.old, Trigger.new, Trigger.newMap, Trigger.oldMap);
  }
  
  /* Before Delete */
  else if(Trigger.isDelete && Trigger.isBefore){
    //handler.OnBeforeDelete(Trigger.old, Trigger.oldMap);
  }
  
  /* After Delete */
  else if(Trigger.isDelete && Trigger.isAfter){
    handler.OnAfterDelete(Trigger.old, Trigger.oldMap);
  }

  /* After Undelete */
  else if(Trigger.isUnDelete){
    //handler.OnUndelete(Trigger.new);
  }

}

this is my class:

public without sharing class ContactTriggerHandler { 
   
    public void OnBeforeInsert(Contact[] newContacts) {
        // BEFORE INSERT LOGIC
    
    }
    
    public void OnAfterInsert(Contact[] newContacts) {
        // AFTER INSERT LOGIC
         insertcontact(newContacts, new Map<Id,Contact>());
    }
    
    public void OnBeforeUpdate(Contact[] oldContacts, Contact[] updatedContacts, Map<ID, Contact> newMap, Map<ID, Contact> oldMap) {
        // BEFORE UPDATE LOGIC
             
    }
    
    public void OnAfterUpdate(Contact[] oldContacts, Contact[] updatedContacts, Map<Id, Contact> newMap, Map<Id, Contact> oldMap) {
        // AFTER UPDATE LOGIC
        
    }
    
    public void OnBeforeDelete(Contact[] contactsToDelete, Map<ID, Contact> oldMap) {
        // BEFORE DELETE LOGIC
           //Deletecontact(contactsToDelete);
    }
    
    public void OnAfterDelete(Contact[] deletedContacts, Map<ID, Contact> oldMap) {
        // AFTER DELETE LOGIC
        //Deletecontact(deletedContacts);
        insertcontact(deletedContacts, oldMap);
    }
    
    public void OnUndelete(Contact[] restoredContacts) {
        // AFTER UNDELETE LOGIC
        
    }
    
    public void insertcontact(Contact[] Contacts, Map<ID,Contact> oldMap ){
        // List<Contact> contactList = [SELECT ID, account.Contact_Count__c FROM Contact];
        set<Id> accid = new set<Id>();
        //List<Contact> contactList = new List<Contact>();
        for(contact con: Contacts){
            accid.add(con.accountid);
        }
        
       for(contact cons: oldMap.values()){
            accid.add(cons.accountId);
        }
        
           List <Account> accList = new List <Account>();
        
        //if(newMap.get(con.Id)!=oldMap.get(con.Id)
        /* Aggregate Query */
        for(Account acc:[SELECT Id,Name,Contact_Count__c,(Select Id from Contacts) from Account where Id IN: accid]){
            if(acc!=null){
            Account accObj = new Account ();
            accObj.Id = acc.Id;
            accObj.Contact_Count__c = acc.Contacts.size();
            system.debug('accsize:--->' +acc.Contacts.size() );
            accList.add(accObj);
        }
            else{
             Account ccObj = new Account ();
                ccObj.Id = acc.Id;
             ccObj.Contact_Count__c = 0;
             accList.add(ccObj);
            }
        }
        update accList;
    }
    
     public static void Deletecontact(Contact[] deletedContacts){
         
         set<Id> accid = new set<Id>();
         for(contact con: deletedContacts){
             accid.add(con.accountId);
         }
         
         List <Account> accList = new List <Account>();
         
         //if(newMap.get(con.Id)!=oldMap.get(con.Id)
         // Aggregate Query
         for(Account acc:[SELECT Id,Name,Contact_Count__c,(Select Id from Contacts) from Account where Id IN: accid]){
             system.debug('acclist:--->' +acc );
             Account accObj = new Account ();
             accObj.Id = acc.Id;
             system.debug('accsize:--->' +acc.Contacts.size() );
             accObj.Contact_Count__c = acc.Contacts.size();
             system.debug('accsize:--->' +acc.Contacts.size() );
             accList.add(accObj);
         }
            system.debug('accList:--->' +accList);
         update accList;
     }
}

when i try to insert contact the field is getting updated but when i delete it it's not getting updated.
can anyone help me where i am going wrong.

 
Hi,
i have a scenario where have to generate quote document when an quote is inserted. I am able to do this using below code. But i want to do this for bulk quote inserts. Can anyone suggest me on this?
public with sharing class GenerateQuoteProposal {
    
    public String save(QuoteProposalModel context) {
        return SBQQ.ServiceRouter.save('SBQQ.QuoteDocumentAPI.Save', JSON.serialize(context));
    }
}
rendering not working properly.

VisualForce Page:
------------------
<apex:inputField id = "EnterValueId" Value = "{!Bd__c.Amt__c}">
    <Apex:actionSupport event = "onchange" action = "{!CheckVal}" ReRender = "TxtId" />
</Apex:inputField>

<apex:PageBlockSection id = "TxtId" rendered ={!IsGrter100} >
    <apex:inputField id="InId" required = "{!IsGrter100}" Value="{!Bd__c.TxtArea}"
</apex:PageBlockSection>

Apex:

In constructor I have set IsGrter100 value to false
IsGrter100 = false;

In the CheckVal  method I have set if Bd__c.Amt__c > 100 then IsGrter100 =true or else IsGrter100=false

Part of code:
Public PageReference CheckVal(){
    if Bd__c.Amt__c > 100 {
        IsGrter100 =true;
    }
    else{
    IsGrter100 =false;
    }
    return null;
}    

In my case when I enter more than 100 then text area gets visible and becomes mandate
but when I change the value and enter less than 100 then still text area remain required. I want when 
entered amount is more than 100 then textarea should be visible and mandate and when changing to less
than 100 then it should hide and not to be mandate.

Note: Above code is not complete and have modified littke, but remaining code is working fine except the written scenario , can 
not post complete code due to valid reason. Plese help on this. 

Thanks in advance
Dj
  • August 24, 2017
  • Like
  • 0
Hi,
I'm desperately looking for a workflow rule to automatically format the phone numbers for Contacts with Country = Switzerland as follows:
+41 xx xxx xx xx. I tried several workflow rules, but somehow didn't manage to accomplish this.
Thank you in advance for your input!
I have am writing a trigger on Account that is supposed to fire when the Account Owner is changed. I tested the logic using classes and everything is doing its job, except the trigger is simply not firing. I then changed it to be triggered by different fields and it works just fine in those cases. I read something about Account Change Owner wizard operations not initiating process flows, is that true for triggers as well? What are my alternatives here?
Not firing:
trigger AccountTrigger on Account (after update) {
    System.debug('Account Team Trigger fired');
    for(Id acctId: Trigger.newMap.keySet()){
       if(Trigger.oldMap.get(acctId).OwnerId!= Trigger.newMap.get(acctId).OwnerId){
       classes.dostuff();     
  }
}
DML;
}
However, this one is firing, only when I edit from the edit page, which is not possible for Account Owner:
trigger AccountTrigger on Account (after update) {
    System.debug('Account Team Trigger fired');
    for(Id acctId: Trigger.newMap.keySet()){
       if(Trigger.oldMap.get(acctId).otherField__c!= Trigger.newMap.get(acctId).otherField__c){
       classes.dostuff();     
  }
}
DML;
}


 
I am New to apex development:

this is my trigger:

trigger ContactTrigger on Contact(after delete, after insert, after undelete, after update, before delete, before insert, before update) {

  ContactTriggerHandler handler = new ContactTriggerHandler();

  /* Before Insert */
  if(Trigger.isInsert && Trigger.isBefore){
   // handler.OnBeforeInsert(Trigger.new);
  }
  
  /* After Insert */
  else if(Trigger.isInsert && Trigger.isAfter){
    handler.OnAfterInsert(Trigger.new);
  }
  
  /* Before Update */
  else if(Trigger.isUpdate && Trigger.isBefore){
    //handler.OnBeforeUpdate(Trigger.old, Trigger.new, Trigger.newMap, Trigger.oldMap);
  }
  
  /* After Update */
  else if(Trigger.isUpdate && Trigger.isAfter){
   // handler.OnAfterUpdate(Trigger.old, Trigger.new, Trigger.newMap, Trigger.oldMap);
  }
  
  /* Before Delete */
  else if(Trigger.isDelete && Trigger.isBefore){
    //handler.OnBeforeDelete(Trigger.old, Trigger.oldMap);
  }
  
  /* After Delete */
  else if(Trigger.isDelete && Trigger.isAfter){
    handler.OnAfterDelete(Trigger.old, Trigger.oldMap);
  }

  /* After Undelete */
  else if(Trigger.isUnDelete){
    //handler.OnUndelete(Trigger.new);
  }

}

this is my class:

public without sharing class ContactTriggerHandler { 
   
    public void OnBeforeInsert(Contact[] newContacts) {
        // BEFORE INSERT LOGIC
    
    }
    
    public void OnAfterInsert(Contact[] newContacts) {
        // AFTER INSERT LOGIC
         insertcontact(newContacts, new Map<Id,Contact>());
    }
    
    public void OnBeforeUpdate(Contact[] oldContacts, Contact[] updatedContacts, Map<ID, Contact> newMap, Map<ID, Contact> oldMap) {
        // BEFORE UPDATE LOGIC
             
    }
    
    public void OnAfterUpdate(Contact[] oldContacts, Contact[] updatedContacts, Map<Id, Contact> newMap, Map<Id, Contact> oldMap) {
        // AFTER UPDATE LOGIC
        
    }
    
    public void OnBeforeDelete(Contact[] contactsToDelete, Map<ID, Contact> oldMap) {
        // BEFORE DELETE LOGIC
           //Deletecontact(contactsToDelete);
    }
    
    public void OnAfterDelete(Contact[] deletedContacts, Map<ID, Contact> oldMap) {
        // AFTER DELETE LOGIC
        //Deletecontact(deletedContacts);
        insertcontact(deletedContacts, oldMap);
    }
    
    public void OnUndelete(Contact[] restoredContacts) {
        // AFTER UNDELETE LOGIC
        
    }
    
    public void insertcontact(Contact[] Contacts, Map<ID,Contact> oldMap ){
        // List<Contact> contactList = [SELECT ID, account.Contact_Count__c FROM Contact];
        set<Id> accid = new set<Id>();
        //List<Contact> contactList = new List<Contact>();
        for(contact con: Contacts){
            accid.add(con.accountid);
        }
        
       for(contact cons: oldMap.values()){
            accid.add(cons.accountId);
        }
        
           List <Account> accList = new List <Account>();
        
        //if(newMap.get(con.Id)!=oldMap.get(con.Id)
        /* Aggregate Query */
        for(Account acc:[SELECT Id,Name,Contact_Count__c,(Select Id from Contacts) from Account where Id IN: accid]){
            if(acc!=null){
            Account accObj = new Account ();
            accObj.Id = acc.Id;
            accObj.Contact_Count__c = acc.Contacts.size();
            system.debug('accsize:--->' +acc.Contacts.size() );
            accList.add(accObj);
        }
            else{
             Account ccObj = new Account ();
                ccObj.Id = acc.Id;
             ccObj.Contact_Count__c = 0;
             accList.add(ccObj);
            }
        }
        update accList;
    }
    
     public static void Deletecontact(Contact[] deletedContacts){
         
         set<Id> accid = new set<Id>();
         for(contact con: deletedContacts){
             accid.add(con.accountId);
         }
         
         List <Account> accList = new List <Account>();
         
         //if(newMap.get(con.Id)!=oldMap.get(con.Id)
         // Aggregate Query
         for(Account acc:[SELECT Id,Name,Contact_Count__c,(Select Id from Contacts) from Account where Id IN: accid]){
             system.debug('acclist:--->' +acc );
             Account accObj = new Account ();
             accObj.Id = acc.Id;
             system.debug('accsize:--->' +acc.Contacts.size() );
             accObj.Contact_Count__c = acc.Contacts.size();
             system.debug('accsize:--->' +acc.Contacts.size() );
             accList.add(accObj);
         }
            system.debug('accList:--->' +accList);
         update accList;
     }
}

when i try to insert contact the field is getting updated but when i delete it it's not getting updated.
can anyone help me where i am going wrong.

 
In the first step when enabling customer portal, I received the following error message:

Validation Errors While Saving Record(s) There were custom validation error(s) encountered while saving the affected record(s). The first validation error encountered was "You can't enable or activate portals because your org has encrypted standard fields. Ask your Salesforce administrator about disabling encryption, or use a Community instead.".

Click here to return to the previous page.

I did in a previous trailhead turn on encryption per the instructions.  Further, I have unchecked all the options for encryption under platform encryption. 

Does anyone know how I can get around this issue so I can complete the module?
I have 2 objects (Contact and SLM) both has their AFTER triggers. On each triggers we have that recursive trigger logic which we set the static variable at the end to avoid the recurssion.

I have a  batch class, which is updating the contact record and update the SLM records in a single transaction.  While doing that operation, I see the after update trigger for Contact object is working good and at the end it set the Static variable to true. When the SLM update happens, I am not seeing the SLM trigger is executing, may be because the static variable is set as true. 

I need this recursive check in both objects trigger because we have lot other Workflow and process builder to  update both object.
How to handle this? any thoughts. Thanks
Hi all.

A core part of our business process is collecting the crops to be planted in a farmer's fields as part of a 'crop plan.' We have created a custom object to collect the data that we need to have for the crop plan. This crop plan will always have more than one crop planted by a farmer in more than one field. (A physical field, not a field in Salesforce.)

Is there a way to allow users to enter more than one crop to a famer's crop plan? Specifically, is there a way to add a button, for example, called 'additional crops' that will add a record to the user interface allowing multiple crops to be entered.

What we envision is a button that will duplicate two fields, 'crop' and 'acres planted.' In the end, a user will be able to enter a crop and the number of acres to be planted, click a button that will add another 'crop' and 'acres planted' fields. (In this case, the fields will be fields in salesforce.)

I know that we can add several 'crop' and 'acres planted' fields to the object, but we'd like this to be created by a user using the button, because different farms will have a different number of crops planted. That is, we don't want to create, say 5 'crop' and 'acres planted' fields to the object because some farmers will have 4 crops, some farmers will have 7 crops. We want the interface for entry to look cleaner than having a number of different fields for users to input data.

I hope this is a clear enough explanation for what we're looking for. I can provide more info and screenshot if that is helpful. (This is my first post, so I know I may be unclear in what I'm asking for.)

Thanks, in advance, for your advice.
I'm almost crying from frustration.

I'm on the Trailhead module Admin Beginner > Salesforce1 Mobile Customization > Create Global Quick Actions. I've done all the instructions for the exercise exactly as stated to create the "Stage" predefined value, however, when I try to set it up for use with the "New Prospect" Global Action, it doesn't come up in the dropdown list. (I've tried this several times on different Trailheads and it does the same thing.) Please help!

User-added image
We have multiple Sandboxes and it is a painful process to deactivate user in all the sandboxes. What are the best options to deactivate user in all sandboxes. If you think that there is a code involved please help me with the code because I am not a developer. 
Thanks in advance!
  • August 14, 2017
  • Like
  • 0
Not able to complete my challenge under " Work with Schema Builder". I am getting the below error message even after all the field and filed type were correct.
Challenge Not yet complete... here's what's wrong:
The field 'Street_Address__c' either does not exists on the Property__c object or it is not of type textarea.
I tried everything but I still got this message. The lightning trailhead is https://trailhead.salesforce.com/es-MX/modules/lex_dev_lc_basics/units/lex_dev_lc_basics_attributes_expressions.User-added image
i have accomplished this in a long and manual way with many rollup fields. I think there has to be a better way so starting over, with your help.

I need to calculate the average number of cases per quarter. Cases is a custom object. Rolloup average does not work becasue it counts all accounts when calculating the average. I need to NOT count the accounts that did not have any cases, so my total number of accounts changes every quarter.

I already have a rollup that counts the cases per quarter (in the account object), so i can tell if an account has cases or not.

How do i get the total number of accounts that had cases (case count>0)?

Can Account object be the summarized object, if i create a new object just for this purpose? theres got to be a better way.
  • August 13, 2017
  • Like
  • 0
As we all know for production deployment , Test classes will be automatically running , right !!! . We have issue with that . Half of our test classes are failing because of access issues .

Items to note :
  • 1)in Our test classes it is not using any database data .ie SeeAllData =false
  • 2)First deployment to Production . No recordtypes available
  • 3) we are pushing admin profile in the package which have access to all the records types present .
Issue: Test class is using below statement for creating dummy record with specific record type Schema.SObjectType.Contact.getRecordTypeInfosByName().get('XXXXX').getRecordTypeId();

Actual Issue : As our production doesnt have any recordtype test class is failing saying it unable to find the record type .

Now million dollar question : How we can over come this issue . it is really blocking our production deployment
Hello, 
I am getting this error message in my Conference app when I try to assign a Speaker to a Session, I get this error message. Can you please explain why I am getting this error? I am also pasting the code for the Trigger. Thanks! 

User-added image
User-added image