• RKSalesforce
  • SMARTIE
  • 1295 Points
  • Member since 2015

  • Chatter
    Feed
  • 41
    Best Answers
  • 0
    Likes Received
  • 12
    Likes Given
  • 0
    Questions
  • 226
    Replies
I need a workflow rule to send an email alert when any of 3 date fields are populated.

I tried the following but I am receiving a syntax error that I'm missing a bracket. 

IF(ISBLANK(Fieldone__c) , 
IF IF( ISBLANK( Fieldtwo__c ) ,
IF( ISBLANK( Fieldthree__c ) , false, true) ,  
true)
I'm new to coding and I'm practicing by creating a trigger that will update the Contact Owner depending on the Email field value.
For example, I have the Email field value is test@gmail.com then it will try to look for User that has test@gmail.com email then it will update the Contact Owner.

This is what I've done so far:
 
Set<String> conEmail = new set<String>();
    List<String> UsrId = new List<String>();
    Map<String, Id> UsrMap = new map<String, Id>();
    
    for(Contact con : trigger.new ){
        if(con.Email != null){
            conEmail.add(con.Email);
        }
    }
    
    List<User> userEmail = [SELECT Id, Name, Email FROM User WHERE Email In: conEmail];
    for(User u : userEmail){
        UsrMap.put(u.Email, u.Id);     
    }
    
    for(Contact c : trigger.new){
        if(UsrMap.containsKey(c.Email)){
            c.OwnerId = UsrMap.get(c.Email);
        }
    }
Any ideas on why Owner is not being updated when I edit any contact record.

Thank you!
Inside the Developer Console, I am receiving the error:
Unexpected Token '<' on Line 2

I believe my syntax defining my List<AggregateResult> is correct.
 
trigger CaseHandlerCountAlert on SOBJECT (after insert) {
    List<AggregateResult> AggregateResultList = [SELECT AccountId, Account.Name name, COUNT(Id) co,  Milestone1_Project__c.id,
                                    Milestone1_Project__c.Implementation_status__c, Milestone1_Project__c.Client_Advisor_Email__c
                                    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){ 
                        system.debug(aggr);

                        Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage();
                        
                            if(Milestone1_Project__c.Implementation_status__c == 'LIVE - TRANSITION'){    
                                // Set Outgoing Email to Implementation Coordinator
                                //message.toAddresses = new String[] { test@test.com }; 
                            }
                            else if (Milestone1_Project__c.Implementation_status__c == 'Live'){  
                                // Private method *** getAddresses() *** retrieves email address from Customer_Success_Managers Public Group
                                
                                //message.toAddresses = new String[] { "test@test.com" };
                            } 
                        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
            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);
    }   
    return (emailString);
    }    
}

 
Hi All,

I want to create a scheduler class. When quote status is equal to "ready to price" or "proposed" and quote expiration date is today, move quote status to expired. Please advice

I'm creating email to custom object records via the InboundEmailHandler.  (sorry if my verbage is wrong on that).

What I have working is the email to custom object, as well as the attachments to the record, but having issues creating a new EmailMessage that is associated with the custom object record.

I have all the fields figured out minus the toAddress since it's inserting via a list to string.  I'm not sure how to convert that to a list.  Any help would be appreciated.  Here is the code:

 

global class CreateTradeSupport implements Messaging.InboundEmailHandler {
    
    global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email, Messaging.InboundEnvelope env){
        
        Messaging.InboundEmailResult result = new Messaging.InboundEmailResult();
        
        String myPlainText= '';
        Contact c;
        myPlainText = email.plainTextBody;
        
        try{
            if([SELECT count() from Contact where email =:email.fromAddress] == 0){
                c = new Contact();
                c.LastName = email.fromName;
                c.Email = email.fromAddress;
                insert c; 
            }
            else{
                c = [SELECT Id from Contact Where email =:email.fromAddress LIMIT 1];
            }
            
            Trade_Support__c ts = new Trade_Support__c();
            ts.Description__c = myPlainText;
            ts.Status__c = 'New';
            ts.Subject__c = email.subject;
            ts.web_email__c = email.fromAddress;
            ts.contact__c = c.Id;
            insert ts;
            
            EmailMessage mail = new EmailMessage();
            mail.Subject = email.subject;
            mail.FromAddress = email.fromAddress;
            mail.HtmlBody = email.htmlBody;
            mail.TextBody = myPlainText;
            mail.FromName = email.fromName;
            mail.RelatedToId = ts.Id;
            
//This is where I'm having issues
            mail.toAddress = email.toAddresses;
            mail.CcAddress = email.ccAddresses;
            
            mail.Status = 'Read';
            insert mail;
            
            // Save attachments, if any
                List<Attachment> attachments = new List<Attachment>();
                if(email.textAttachments != null)
                {
                    for (Messaging.Inboundemail.TextAttachment tAttachment : email.textAttachments) {
                        Attachment attachment = new Attachment();
                        attachment.Name = tAttachment.fileName;
                        attachment.Body = Blob.valueOf(tAttachment.body);
                        attachment.ParentId = ts.Id;
                        attachments.add(attachment);
                    }
                }
                if(email.binaryAttachments != null)
                {
                    for (Messaging.Inboundemail.BinaryAttachment bAttachment : email.binaryAttachments) {
                        Attachment attachment = new Attachment();

                        attachment.Name = bAttachment.fileName;
                        attachment.Body = bAttachment.body;
                        attachment.ParentId = ts.Id;
                        attachments.add(attachment);
                    }
                }
                if(attachments.size() > 0)
                {
                    insert attachments;
                }
            

        }
        catch (QueryException e) {
            System.debug('Query Issue:  ' + e);
        }
        
        result.success = true;
        
        return result;
        
        
    }

}
Convert a Lead to an Opportunity using triger
Hi guys given two fields on the lead object:
FieldA__c
FieldB__c
 
I need to write a trigger to convert from Lead to opportunity every time a user fill out those two fields. Can anyone help me with the trigger?
 
Thanks in advance!
Have a lookup field for states and want to create a workflow that if the lookup field is Maryland, then the workflow triggers. How can I write this formula? 
I'm looking for a way to populate a lookup field based on a similar text value on the source and target object.

I have an object child__c with a lookup to parent__c and a field color__c. The field color__c is also available on the parent__c object with unique values.

How can I query the child__c records and populate the lookup with the parent__c record with the same color in color__c in APEX?
I am creating a Trigger that whenever a Contact gets created or inserted the Account Name field will update to a specific account suppose name "xyz".  Right now I have used For loop Inside a For Loop. Is there any way that I can avoid for loop inside for loop? Can I use Map here if yes How?

My current Code is :
trigger AddConToAcc on Contact (before insert) {
list<Account> listAcc = new List<Account>([SELECT Id, Name from Account where name = 'XYZ']);       
    for(Contact con : Trigger.New){
            for(Account acc : listAcc){
                con.AccountId = acc.Id;
                }           
            }
     }
I tried to use a Map but its not working Code mentioned below :
trigger ContToAcc on Contact (before insert) {
    Set<Id> setAccId = New Set<Id>();
       List<Account> acc = New List<Account>([SELECT ID FROM Account WHERE Name = 'XYZ']); 
    for(Account acc1 : acc){
        setAccId.add(acc1.Id);
    }
   Map<Id, Account> mapacc = new Map<Id, Account>([Select Id, Name FROM Account WHERE ID IN :setAccId]);
    for(Contact con : Trigger.New){
        con.Account = mapacc.get(con.Account.Id);        
    }
}
I have two fields: Status__c and Function_End_Date__c. If status equals "Completed" or "Cancelled" I need a rule that sets the Function_End_Date__c to the current Date/Time.
I work with 3 objects : Book, Loan, Contact. Book and Loan are customs.

Book has a field Title, Contact has a field "Number of Loan". Loan is a junction object (Many to Many) from Book and Contact.

The idea is that, whenever a there a Loan is inserted, the value in number_of_loan (of the related contact) get incremented and when we delete it get decremented.

To perform that I decided to create a trigger on the Object Loan.

Here it is: 
trigger BorrowedBooksTrigger on Loan__c (after insert, after delete) {
    
        Contact c = new Contact();
        Set<Id> lretIdsToQuery = new Set<Id>{};
    
        if (Trigger.isInsert) {
            
            for(Pret__c l: Trigger.new){
              lretIdsToQuery.add(p.Id);
             }
    
             
            List<Contact> relatedContacts = [SELECT Id, Name, Number_of_loan FROM Contact
            WHERE Id IN :lretIdsToQuery];
             
            for(Contact c : relatedContacts) {      
                 system.debug('Number_of_loan added '+ c.Number_of_loan);
                 c.Number_of_loan = c.Number_of_loan+1;
                 update c;
            }  
            
             
        }else if (Trigger.isDelete) {
            
             for(Pret__c l: Trigger.old){
              lretIdsToQuery.add(p.Id);
             }
    
             
            List<Contact> relatedContacts = [SELECT Id, Name, Number_of_loan FROM Contact
            WHERE Id IN :lretIdsToQuery];
             
            for(Contact c : relatedContacts) {      
                 system.debug('Number_of_loan deleted '+ c.Number_of_loan);
                 c.Number_of_loan = c.Number_of_loan-1;
                 update c;
            } 
            
        }
    }

But the code doesn't work at all. I've even have nothing display on the debug console.

Please help :(
Hello,
I am getting an error Compile Error: Invalid type: Opp_Top_X_Designation__c on the first two lines.

The field Opp_Top_X_Designation__c is a lookup to Opportunity from another object Top_X_Designation. Now either the setup is not correct of the format of the code line is not right. Please provide inputs.

list<Opp_Top_X_Designation__c> oppidlist = new list<Opp_Top_X_Designation__c>();
 list<Opp_Top_Designation__c> updatelist = new list<Opp_Top_Designation__c>();
 
 for(Top_Designation__c tx : trigger.new){
 if(trigger.isUpdate || trigger.isInsert){
  if(tx.Document_Attached__c == true && tx.Typeof__c == 'Contract'){
 
 // mt.put(tx.Opp_Top_X_Designation__c, tx.Id);
 // s.add(tx.Opp_Top_X_Designation__c);
Hi,
I am trying to create a custom button with an if statement to use on a quote detail page. Sample code as follows;
{!IF
(
TEXT(Quote.Status)<>"Akzeptiert",
URLFOR("/apex/SalesFlowCreateOrderContract"),
'/flow/Quote_to_Order_with_Contract?QuoteID="{!Quote.Id}&"retURL=/"{!Quote.Id}'
)}

On the first option, the code tries to redirect to a VF page which works perfectly. But if statement continues on to the second option either I get encoding errors or non-working if statement depending on the syntax I tried to avoid errors. I tried to use URLENCODE but it did not work too.

Is there anyone who may share ideas on this?

thanks
Alper
 
Hi Guys, i got this error validating my Trigger

System.ListException: List index out of bounds: 1  Stack Trace: Class.CaseUtility.updateExpiredPoaLinks: line 582, column 1 Class.CaseUtilty_test.testUpdateExpiredPoaLinks: line 192, column

code below:
trigger t1 on Case (before insert, before update) {

 Group q = [SELECT Id FROM Group WHERE Name ='NCT queue' AND Type = 'Queue']; 

Contact con = new Contact(); 

for(Case cas : Trigger.New){

         if(cas.Court_Process__c == 'NCT'){

        cas.OwnerId = q.Id; 
    
       }
   }

 NCT__c nctNew = new NCT__c(Full_Name__c = con.cm1__Full_Name__c ); 

  insert nctNew; 
}


need help
My company would like to send out a customer satisfaction email (template already created) when a job title (account) wraps. In addition to this the account/contact relationship has a check box for "send survey" and we only want the related contacts that have this check off to receive the email. 
I tried making a workflow to do this but it won't allow me to pull info from the acount related section.

I'm told there is possibly an Apex code that could make this happen. Does anyone have any suggestions?

Thanks!
      
trigger Stuck_on_Auto_Escalate_Status on Case (before insert, before update ) {
  
        for(Trigger_Control__c tc:Trigger_Control__c.getall().values()){ //this is a custom setting (checkbox field) 
             
             if(tc.Action_Auto_Escalation__c==true)
             
             {
                for(case cs:trigger.new)
                   {   
        
                            if(cs.Status=='Action - Automated Escalation')
                              {
                   
                                     
                                      cs.Stuck_on_Action_Automated_Escalation__c=true;
                                  
                                     
                               }
                     }
        }
    
        }
     }
 
Hello,
I have a custom object called "Line Item", that has a master-detail relationship on Opportunity.
On an opportunity, I can have multiple "Line items". Each line item has a value.

I would like to multiply these values, and get the result in a field on opportunity.

Example:
"My opportunity":
  • Line item 1: 2
  • Line item 2: 10
  • Line item 3: 2

Field "my multiplication" on "My opportunity": 2*10*2=40

What I'm trying to achieve is actually a custom field with a field type "Roll up summary", but Salesforce only allows to calcualte Min, Max, Count, Sum...

Any ideas how I can achieve this?

Hi ,
I have to uncheck the checkbox on child object when my parent object record gets deleted.

Parent object : raddes have a some records
Child Object : radparent

I have a check box on radparent. now, my requirement is when i deleted a parent record in raddes the checkbox on child object "radparent" should uncheck which mean we need to check the size of the object and update the child update checkbox.