• Eldon
  • SMARTIE
  • 1064 Points
  • Member since 2016
  • Salesforce Consultant
  • Onivation


  • Chatter
    Feed
  • 30
    Best Answers
  • 1
    Likes Received
  • 1
    Likes Given
  • 26
    Questions
  • 222
    Replies
I need to add a column with number of days since a task created date. Please could someone help with the code so I can just insert my created date field into it.

TIA.

Dave.
Hi All,

In my contact object I have a field named NewsletterStatus. When my apex class is executed by a guest user, the method Schema.sObjectType.contact.fields.Newsletter_Status__c.isUpdateable() is returning false even though the guest profile and admin profile have edit access to this field and the object. Any reason for this?

Thanks in advance
Eldon K
Hi All,

I am trying to display the notes associated with a custom object record. I have the correct ContentNote Ids but when I give the following SOQL in an apex class, I am receiving an error.
[SELECT Id,Title, Content,CreatedDate, TextPreview FROM ContentNote WHERE Id IN: contentIds]

No such column 'TextPreview' on entity 'ContentNote'. If you are attempting to use a custom field, be sure to append the '__c' 

The same SOQL works fine in the query editor though. I am able to the see the correct records and the TextPreview field in console.
I am trying to display these notes in a VF page and if I use the field 'Content' in the page its displayed as below:
          core.filemanager.ByteBlobValue@19c5beb6

Is there any way to display the text value of the notes in VF page?

Thanks in advance
Eldon K
 
I have a trigger which is added to object A in which I need to show error on save button but at the same time I need to insert record in a custom object B. I am using trigger.new[0].addError('Message') and then using database.insert to insert the data in the custom object B but the record is not getting created as I read in documentation that addError rollbacks the DML operation but I need both the error and DML operation to function.  Can anyone help me with this?
I have always been able to avoid writing code till today. Our marketing team created several hundred Pardot Landing pages for our business partners sales reps to enter leads into. 
These leads come into Salesforce and have a text field  populated called Landing_Page_ID__c . The field is basically firstname.lastname  of the partner sales rep.  

I need to be able to populate a lookup on the lead called Territory_Manager__c . (this is the contact record of the partner sales rep who submiited the lead)  I have created a new field on the Conact called LPID_c which matches the text from the Landing_Page_ID__c.

I am going to watch videos and trailheads but I thought I would ask here first since I am on a deadline to fix this.
 
Account - Standard Object
Case - Child of Account
Milestone__Project__c - Child of Case

The After-Insert Trigger will send an email message anytime an account has 8 cases or more created in a 5 day period.  The email will be sent to one of two addresses (depending on Project.status).  How do I access the Milestone__Project__c.Status field?  I cannot get the syntax correct.
 
public class CaseHandlerCountAlert{
public static void CaseCounter(){

    List<AggregateResult> AggregateResultList = [SELECT AccountId, Account.Name name, COUNT(Id) co, (Id FROM Milestone1_Project__c mi)
                                FROM Case
                                WHERE CreatedDate = LAST_N_DAYS:5
                                GROUP BY AccountId, Account.Name
                                HAVING COUNT(Id)  >= 8
                                WHERE Id IN :Trigger.new];
                                

            for(AggregateResult aggr:AggregateResultList){ 

                    Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage();
                        if((aggr.get(mi.status) == "Transition"){    // If Status = Transition
                            // Set Outgoing Email to Implementation Coordinator "Implementation.Consultalt "
                            message.toAddresses = new String[] { Milestone1_Project__c.Client_Advisor_Email__c };
                        }
                        else if ((aggr.get(mi.status) == "Live"){  // If Status equals "Live" - Out Of Transition
                            // Private method retrieves email address from Customer Success Managers
                            message.toAddresses = new String[] { getAddresses() };
                        } 
                            // Set Email Template Id
                    //EmailTemplate templateId = [Select id from EmailTemplate where name = 'Template Name'];  
                    //mail.setTemplateID(templateId.Id);
                    message.setSubject = 'Subject Test Message';
                    message.setPlainTextBody = 'Account name: ' + aggr.get('name') + ' has ' + (Integer)aggr.get('co') + ' cases opened in the last 8 days.';
                    Messaging.SingleEmailMessage[] messages =   new List<Messaging.SingleEmailMessage> {message};
                    Messaging.SendEmailResult[] results = Messaging.sendEmail(messages);
                System.debug('Account Name: ' + aggr.get('name'));           
            }
            } 

            private List<String> getAddresses(){
            List<User> UserList =
                    [SELECT id, name, email, isactive, profile.name, userrole.name, usertype
                    FROM User 
                    WHERE id 
                    IN (SELECT userorgroupid 
                    FROM groupmember
                    WHERE group.name = 'Customer Success Managers')];

            Set<String> emailString = new Set<String>();

            for(User u: UserList){
                emailstring.add(u.email);
                // System.debug(u.email);
            }   
            //System.debug('The list ' + emailstring);
            return (emailString);
            }    
            }

 
Hi! I finally got this simple Apex Trigger working in Sandbox:
trigger restrictFileDeletion on ContentDocument (before delete) {
    String profileName=[SELECT id,Name FROM Profile WHERE Id =:UserInfo.getProfileId()].Name; 
       for (ContentDocument cd : Trigger.old){     
        If(profileName=='ALS Community v6'){
            cd.addError('You cannot delete this record!');
        }
    }
}

Then I went to deploy in production and I received this error "Code Coverage Failure The following triggers have 0% code coverage.  Each trigger must have at least 1% code coverage.restrictFileDeletion.

I have read all related threads and Trailhead, and I'm still stuck on how to write a test class to get this to deploy in production. I would be so appreciate of any help to get this working. I was so excited to get this working in Sandbox, now I've wasted hours, and it's still not working in production. Thanks in advance!!

Salute.

I'm trying to add to the contact list page an indication of the role of each indirect contact. Like this:

   public List<Contact> Contacts { get{  
     return [SELECT Id, Name, Account.Name, Title, Email, Phone, Relations__c FROM Contact LIMIT 1000];  
   } set;}  
   
   public List<Role> Roles { get{  
     return [SELECT Role FROM AccountContactRoles];  
   } set;}  I tried adding Role or AccountContactRole fields, but they are not recognized. What I need to do?
I tried to indicate the Role field in the first request, but received a recognition error (which is logical, there is no such field in the standard contact card).

Then I made the second request only for roles, but it also produces Compile Error: Invalid type: Roles.

What i need to do?
How can i automatically create quote line item and add opportunity line item as quote line item when i will create Quote .I Have tried this trigger which is not working as per my requirement .
trigger createQuoteLineDetails on CQuote__c(after insert,before insert) {

CQuote__c ord=trigger.new[0];

// Fetch Opp Id
COpportunity__c oppId=[select id from COpportunity__c where id=:ord.QOpp_Name__c];

// Fetch Opp Lines 
List<Opportunity_LineItem__c> opplines=[select id,CurrencyIsoCode,Opportunity__r.name,Principal_Name__c, Product_Category__c,Product_Description__c,
                        Product__c,Quantity__c,Unit_Price__c from Opportunity_LineItem__c where Opportunity__c=:oppId.id];

    // Loop Opportunity Lines
    for(Opportunity_LineItem__c oppline:opplines){
        
        // Create Order Line Object
        Quote_Line_Item__c QLine = new Quote_Line_Item__c ();
        QLine.Quote_Name__c= ord.Id;
       
       
        insert QLine ;
    }

}

 
Hi,

i have one checkbow field in opportunity record when i am clone the opportunity record i want checkbox field valueas automatically true for new records 

 
I have Quote object which has Child object Quotation Line Item and I have PO object which has child object named Project .

PO has Lookup with Quote, So when I will create a new PO from Quote, Same number of Projects should create under PO against each Quotation Line Item,

I tried the following code but it is not capturing Quotation Line Item Name against which one which project created. Please Help me to Resolve this
User-added image
 
How to query all the users in a particualr queue

thanks
Hi,,

I have created 4 fields on price book enteries.

Product Material No.
Sales Unit Of Measure
Region
Currency.

I require a combination of these 4 fields to be the primary key(5th field) for my product. Such that , that primary key be the determinant for the price of my product.

If any of the 4 fields differ in value from the previously existing combination , It will set a new price for a product.

I understand , there is no apex trigger or workflow rule on pricebook. How do i achieve this functionality?



 
Consider Account(std object),Vehicle(custom object-lookup to account) and forms(another custom object- loookup to account).There is a field on custom object Vehicle called "Expiration date". Customers will apply for a form once their vehicles gets expired to get renewed. The forms are shared to account and vehicles(sharing rule).I want to send an email alert  to a team (details of vehicle) when the vehicle gets expired and didnot apply for renewal. Bit confused but can we do this? Batch class or trigger?
Hi, 

  In below helper class i have commented there are two condition update for contact and lead Please suggest me how to make this out of for loop and code bulkified.  Please suggest
public class CtapAssessmentTriggerUtils { 
  
    public static void processInsert(List<CTAP_Assessment__c> newLst) {
        List<Contact> cntlst = new List<Contact>();
        List<Lead>    ledlst = new List<Lead>();
        Set<String> emailSet = new Set<String>();
        Set<String> partnerSet = new Set<String>();
        Lead l = new lead();
        
        Map<String, Id> mapEmailToConId = new Map<String, Id>();
        Map<String, Id> mapEmailToLeadId = new Map<String, Id>();
        List<Lead> newLeadLst = new List<Lead>();
        Map<String, CTAP_Assessment__c> newLeadforCtapMap = new Map<String, CTAP_Assessment__c> ();
        Map<Id,Id> PartnerActMap = new Map<Id,Id>();
         
        // collect emails in a set
        for(CTAP_Assessment__c ctap : newLst) {
            CountryCodeMap__c codeMap = CountryCodeMap__c.getInstance(ctap.Country_Code__c);                   
            system.debug('__kkk__' +codeMap);
            if(codeMap != null) {
                ctap.End_Customer_Country__c = codeMap.Country_Name__c;
            }
            emailSet.add(ctap.Contact_Email__c);
            partnerSet.add(ctap.Partner_Account__c);
            system.debug('ctap.Contact_Email__c ' + ctap.Contact_Email__c);
        }
        // removing nulls
        emailSet.remove(null);
        
        system.debug('emailSet '  + emailSet);
        
        if(!emailSet.isEmpty()) {
            for(Contact objCon : [select id,email from contact where email IN :emailSet]){
                mapEmailToConId.put(objCon.Email, objCon.Id);
                objCon.Lead_Source_Temp__c = 'CTAP Assessement'; //Update Contact Lead Source added by Sudhir
                cntlst.add(objCon);
            }
            
            for(Lead objLead: [select id,email from Lead where email IN :emailSet]){
                mapEmailToLeadId.put(objLead.Email, objLead.Id);
                objLead.Lead_Source_Temp__c = 'CTAP Assessement'; //Update Lead Source added by Sudhir
                ledlst.add(objLead);
            }
        }        
                
         for(Account ObjPartnerAct : [select id,owner.name,ownerid from account where id in :partnerSet]){
            PartnerActMap.put(ObjPartnerAct.id,ObjPartnerAct.ownerid);
         }
         
        // asssign based on map key match with email
        for(CTAP_Assessment__c ctap : newLst){
            if( mapEmailToConId.get(ctap.Contact_Email__c) != null){
              ctap.Contact__c = mapEmailToConId.get(ctap.Contact_Email__c);
              ctap.Lead__c = null;
                if (!cntlst.isEmpty()){  // Conditional update contact
                   update cntlst;
                  }
             }else if ( mapEmailToLeadId.get(ctap.Contact_Email__c) != null) {
              ctap.Lead__c = mapEmailToLeadId.get(ctap.Contact_Email__c);
              ctap.Contact__c = null;
                   if (!ledlst.isEmpty()){ //Conditional update lead
                   update ledlst;
                  }
              }
              else {         
                  // Create a new lead         
                  l.Company = ctap.End_Customer_Name__c;
                  l.FirstName = ctap.Contact_First_Name__c; 
                  l.LastName = ctap.Contact_Last_Name__c; 
                  l.Email = ctap.Contact_Email__c;
                  l.Phone = ctap.Phone__c;
                  l.Title = ctap.Title__c;
                  l.Industry = ctap.Industry__c;
                  l.Lead_Source_Temp__c = 'CTAP Assessement';
                  l.LeadSource = 'CTAP Assessement';
                  l.street = ctap.Address__c;
                  l.Country = ctap.End_Customer_Country__c;
                  l.State = ctap.state__c;
                  l.Postalcode = ctap.postalcode__c;
                  l.Employee_Size__c = ctap.Employee_Size__c;  

                  if(ctap.Country_Code__c == 'US') {// verify for the Assignment rule test for US 
                      l.Run_Assignment_Rule__c = true;
                  } else if(ctap.Partner_Account__c !=  null && ( ctap.Country_Code__c != 'US') ){ //Here it checks only for country USA
                    l.Ownerid = PartnerActMap.get(ctap.Partner_Account__c);  
                  }  
                                              
                 if(ctap.Contact_Email__c <> null && 
                    ctap.End_Customer_Country__c <> null &&
                    ctap.End_Customer_Name__c <> null &&
                    ctap.Contact_First_Name__c <> null ) {                                                    
                   newLeadLst.add(l);
                  }
                  
                 newLeadforCtapMap.put(ctap.Contact_Email__c, ctap);
             
          } 
        }
        
           if ( !newLeadLst.isEmpty() ){
                insert newLeadLst;
                    
                 for(Lead lead : newLeadLst){
                    CTAP_Assessment__c ctap = newLeadforCtapMap.get(lead.Email);
                    ctap.Lead__c = lead.id; //Assign new lead to ctap lead
                 }
            }
    }
     
    public static void processUpdate(Map<id,CTAP_Assessment__c> newMap, Map<id,CTAP_Assessment__c> oldMap) {
        List<CTAP_Assessment__c> changedLst = new List<CTAP_Assessment__c>();
        for(CTAP_Assessment__c ctap : newMap.values()){
            CTAP_Assessment__c oldCtap = oldMap.get(ctap.id);
              if(ctap.Contact_Email__c != null){
                changedLst.add(ctap);
            }
        
            if(!changedLst.isEmpty())
                processInsert(changedLst);
        }
    }
    
  
    
  
}

Thanks
Sudhir
Dear Friends, 

Need your help, My Question is...

There is a Trigger Code on Task object, Which is going to update a custom field on Opporunity (There is DML Update operation on Task Object for Opportunity). And there is also a trigger code on Opportunity (after Update). So Whenever i create a task, and i am comparing (Task.WhatId==Opp.WhatID), In the Console it is saying that ' Attempt to Derefernce a null Object ',. How to over come on this. How to use Recursive trigger here. Please help me on this. Thank you.  
Hello Group,

I'm trying to create a simple inline VF page but not able to filter just the records I need.

I'm working with 3 objects = Accounts >Customer Visit >Visit Notes.  
I just want to display the last 2 or 3 "Visit Notes" records when a new "Customer Visit" is created,  so our Reps can more easily follow up on their action items.

Customer Visit is a Lookup to Accounts, and Visit Notes is a Master-Detail to Customer Visit.
Visit Notes also has a Lookup relationship to Accounts.

I've tried several different WHERE clauses but only to produce a variety of compiler errors.
Any help would be greatly appreciated!