• Samruddhi Gokhale
  • NEWBIE
  • 10 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 8
    Replies
Hi,

I have a lead trigger which updates the owner of lead to the currently logged in user whenver any user edits a lead. I have the settings to set EmailHeader.triggerUserEmail = false in 'After Update' trigger. Still the system generated mail is getting fired.
Trigger code is as follows:
trigger LeadTrigger on Lead (after update)
{
Database.DMLOptions dlo = new Database.DMLOptions();
        dlo.EmailHeader.triggerAutoResponseEmail = false;
        dlo.EmailHeader.triggerUserEmail = false;
        dlo.EmailHeader.triggerOtherEmail = false;
            
        List<Lead> leadList = new List<Lead>();
        for(Lead leadObj:Trigger.newMap.values())
        {
                leadList.add(new Lead(id=leadObj.Id,ownerId=leadObj.ownerId));
        }
        if(!leadList.isEmpty())
        {
            for(Lead l:leadList)
            {
                if(l.ownerId != Userinfo.getUserId() && Trigger.newMap.get(l.Id).ownerId == Trigger.oldMap.get(l.Id).ownerId)
                {
                    l.ownerId = UserInfo.getUserId();
                    l.setOptions(dlo);
                }
            }
            
            database.update(leadList,dlo);
}
Hi,

I have a custom object and Case object has lookup to that custom object. In 'After Insert' trigger of custom object, I call a static method of a class (which runs in without sharing mode) that inserts a case for every custom object record and populates the lookup relationship. It also sets dml options for firing case assignment rules. 
Sharing settings of Case and Custom object is Private. If I do not give View All permission for Cases, then this code does not work and gives invalid cross reference key error. The same code works in other organizations, hence I am really confused what is happenning. The code for that class is as follows:

AssignmentRule AR = new AssignmentRule();
AR = [select id from AssignmentRule where SobjectType = 'Case' and Active = true limit 1];   
List<Case> caseList = new List<Case>();  
//clist contains Trigger.New
    for(Custom_Object__c cust:cList)
    {
        case c = new Case();
        c.Status = 'New'; 
        c.Custom_Object__c = cust.Id;
         //Setting the DMLOption on Case instance
                    Database.DMLOptions dmlOpts = new Database.DMLOptions();
                    dmlOpts.assignmentRuleHeader.assignmentRuleId= AR.id;
                    dmlOpts.EmailHeader.triggerUserEmail=true;
                    c.setOptions(dmlOpts);
                    caseList.add(c);
    }
    insert caseList;
My group has all the users with a specific name. I have tried below query:
select group.relatedId from GroupMember where id = '<my group id>'
Though my group is related to a single role, I still get null in relatedid. What is the reason?
I want to send emails in user's language dynamically. Two approaches:
1. Use visualforce email template, create labels and use them in the template. Set language attribute in the template and provide translations for the labels using translation workbench.
2. Create multiple versions of each template, each in a separate language and choose the template dynamically.

Advantage of first approach is that no additional efforts are required if a new language is to be supported but creating so many custom labels is cumbersome. 2nd approach is good in that respect but a template needs to be added everytime a new language is supported. 
Is there any other approach? If not, which one of the above should be chosen?
Hi,

Is there any way to know if the assignment rules have been run in a trigger? The 'run assignment rule' checkbox guarantees that all the assignment rules are evaulated, but how to know if any of the entries satisfied all the criteria and the assignment acutally happenned?
I want to send emails in user's language dynamically. Two approaches:
1. Use visualforce email template, create labels and use them in the template. Set language attribute in the template and provide translations for the labels using translation workbench.
2. Create multiple versions of each template, each in a separate language and choose the template dynamically.

Advantage of first approach is that no additional efforts are required if a new language is to be supported but creating so many custom labels is cumbersome. 2nd approach is good in that respect but a template needs to be added everytime a new language is supported. 
Is there any other approach? If not, which one of the above should be chosen?
Hi,

I have a lead trigger which updates the owner of lead to the currently logged in user whenver any user edits a lead. I have the settings to set EmailHeader.triggerUserEmail = false in 'After Update' trigger. Still the system generated mail is getting fired.
Trigger code is as follows:
trigger LeadTrigger on Lead (after update)
{
Database.DMLOptions dlo = new Database.DMLOptions();
        dlo.EmailHeader.triggerAutoResponseEmail = false;
        dlo.EmailHeader.triggerUserEmail = false;
        dlo.EmailHeader.triggerOtherEmail = false;
            
        List<Lead> leadList = new List<Lead>();
        for(Lead leadObj:Trigger.newMap.values())
        {
                leadList.add(new Lead(id=leadObj.Id,ownerId=leadObj.ownerId));
        }
        if(!leadList.isEmpty())
        {
            for(Lead l:leadList)
            {
                if(l.ownerId != Userinfo.getUserId() && Trigger.newMap.get(l.Id).ownerId == Trigger.oldMap.get(l.Id).ownerId)
                {
                    l.ownerId = UserInfo.getUserId();
                    l.setOptions(dlo);
                }
            }
            
            database.update(leadList,dlo);
}
Hi,

I have a custom object and Case object has lookup to that custom object. In 'After Insert' trigger of custom object, I call a static method of a class (which runs in without sharing mode) that inserts a case for every custom object record and populates the lookup relationship. It also sets dml options for firing case assignment rules. 
Sharing settings of Case and Custom object is Private. If I do not give View All permission for Cases, then this code does not work and gives invalid cross reference key error. The same code works in other organizations, hence I am really confused what is happenning. The code for that class is as follows:

AssignmentRule AR = new AssignmentRule();
AR = [select id from AssignmentRule where SobjectType = 'Case' and Active = true limit 1];   
List<Case> caseList = new List<Case>();  
//clist contains Trigger.New
    for(Custom_Object__c cust:cList)
    {
        case c = new Case();
        c.Status = 'New'; 
        c.Custom_Object__c = cust.Id;
         //Setting the DMLOption on Case instance
                    Database.DMLOptions dmlOpts = new Database.DMLOptions();
                    dmlOpts.assignmentRuleHeader.assignmentRuleId= AR.id;
                    dmlOpts.EmailHeader.triggerUserEmail=true;
                    c.setOptions(dmlOpts);
                    caseList.add(c);
    }
    insert caseList;
My group has all the users with a specific name. I have tried below query:
select group.relatedId from GroupMember where id = '<my group id>'
Though my group is related to a single role, I still get null in relatedid. What is the reason?
Hi, this is VF code form the Mass Edit Cases from App Exchange. Can anyone help me with code to set it to where it sorts by Development Priority ASC? It doesn't have to toggle, just always load that way. Thanks!


<apex:page standardController="Case" recordSetVar="unused" sidebar="false">
<apex:includeScript value="{!$Resource.UtilJS}" />
<apex:form >
<apex:pageBlock >
<apex:pageMessages />
<apex:pageBlock >
Note: All modifications made on the page will be lost if Return button is clicked without clicking the Save button first.
</apex:pageBlock>
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!save}"/>
<apex:commandButton value="Return" action="{!cancel}"/>
</apex:pageBlockButtons>
<apex:pageBlockTable value="{!selected}" var="a" id="table">
<apex:column headerValue="Case Number">
<apex:inputField value="{!a.CaseNumber}"/>
</apex:column>
<apex:column headerValue="Subject">
<apex:inputField value="{!a.Subject}"/>
</apex:column>
<apex:column headerValue="Status">
<apex:inputField value="{!a.Status}"/>
</apex:column>
<apex:column headerValue="Development  Priority">
<apex:inputField value="{!a.Development_Priority__c}"/>
</apex:column>
<apex:column headerValue="Business Priority">
<apex:inputField value="{!a.Customer_AM_Requested_Priority__c}"/>
</apex:column>
<apex:column headerValue="Case Rank">
<apex:inputField value="{!a.Case_Rank__c}"/>
</apex:column>
<apex:column headerValue="Type">
<apex:inputField value="{!a.Type}"/>
</apex:column>
<apex:column headerValue="Description">
<apex:inputField value="{!a.Description}"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
 
  • June 04, 2015
  • Like
  • 0
This is my first time trying to code a trigger in Salesforce. I have a checkbox labeled "Priority Contact," and I'd like the checkbox to be checked for all contacts that have at least one Opportunity or Meeting event linked to them. Could you please advise on how I should go about doing this? I'm also not 100% sure where to enter the code to activate the trigger. Thank you.