• Wik
  • NEWBIE
  • 70 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 2
    Likes Received
  • 0
    Likes Given
  • 67
    Questions
  • 83
    Replies

Hi,

I have overridden the Clone button on quote. There are 5 steps in Quote. Some elements on Step 5 do not get cloned.
What could be the issue?

Thank You

  • April 13, 2015
  • Like
  • 0
Hi,
There is a lookup relationship on Lead to a Custom Object "Technician".
I am trying to get the Created date of the latest Lead created on the related Technican Record.
I am writing a trigger on Lead (after insert),

trigger LeadDate on Lead (after insert) {

Set<Id> techIds = new Set<Id>();

for (Lead lead : Trigger.new) {
    techIds.add(lead.Technician__c);
}

techIds.remove(null);

if (!techIds.isEmpty()) {
    List<Technician__c> techsToUpdate = new List<Technician__c>();

    for (Technician__c tech : [
        select LatestLeadDate__c,
            (
                select CreatedDate
                from Lead__r
                order by CreatedDate asc
                limit 1
            )
        from Technician__c
        where Id in :techIds
    ]) {
        if (!tech.Lead__r.isEmpty()) {
            if (tech.LatestLeadDate__c != tech.Lead__r.get(0).CreatedDate) {
                tech.LatestLeadDate__c = tech.Lead__r.get(0).CreatedDate;
                techsToUpdate.add(tech);
            }
        }
    }

    if (!techsToUpdate.isEmpty()) {
        update techsToUpdate;
    }
}

}

Error: Error: Compile Error: Didn't understand relationship 'Lead__r' in FROM part of query call. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names. at line 14 column 31

Thank You.
  • April 02, 2015
  • Like
  • 0

Hi,

There is a lookup relationship on Lead to a Custom Object "Technician".

I am trying to get the Created date of the latest Lead created on the related Technican Record.

I am writing a trigger on Lead (after insert), can some one help me with the logic of getting the related techcian id and populate the Created date on technician.

Thank You.

  • April 01, 2015
  • Like
  • 0
Hi,

Currently there's a button "Change Owner" on the custom object's record list. Similar to this how can i create another button "Change Supervisor" which would change the Supervisor of all the Custom Object's records.
  • February 02, 2015
  • Like
  • 0
Hi ,

I am looking for implementing the below mentioned changes an a custom object named "Equipment":


1) If ship date is 2013 then lock down both fields named  ship date and startup date (throw an error when anyone tries to edit an equipment with Ship Date 2013)
 
2) If ship date is greater than equal to 1st Jan 2014 then only 2 roles should be able to edit the startup date.

Thank You
  • January 27, 2015
  • Like
  • 0

Hi,

Need help in writing a trigger which sends email to a person when the Quote submitted for approval meets the following criterions:
Contract Year > 5

&& Job Type = SA

Any help is appreciated.

  • December 18, 2014
  • Like
  • 0
Hi,

trigger send_notification on Quote (after update) {

  Quote inquery = trigger.new[0]; 
  Quote.email__c = 'Gaurav.Raj@fs.utc.com';
  String[] toAddresses = new String[] {inquery.email__c}; 
 
  Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();

  //mail.setTargetObjectId(inquery.OwnerID);
  mail.setSenderDisplayName('Salesforce Support');
  mail.setUseSignature(false);
  mail.setBccSender(false);
  mail.setSaveAsActivity(false);

 if (Trigger.isUpdate) { 
    if(inquery.XYZ__c == 'True') {
          EmailTemplate et=[Select id from EmailTemplate where ID=:'00X6000000126rL'];
          mail.setTemplateId(et.id);
          Messaging.SendEmailResult [] r = 
    Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail});   
      } 
      }
      }

it throws an error : 
Error: Compile Error: Expression cannot be assigned at line -1 column -1
 
  • December 17, 2014
  • Like
  • 0
HI ,

Following is my trigger:

trigger Duplicate on Contact (before insert, before update) {
    set<Id> accIds = new set<Id>();

    for(Contact p :trigger.new){
        accIds.add(p.accountId);
    }
    map<Id,account> parentAccmap = new map<Id,account>([select Id,parentId,recordtypeId from account where Id IN :accIds and parentId!=NULL and recordtypeId='012600000005J5J']); //add Site record type Id here.

    set<ID> parentIds = new set<ID>();
    for(Account acc : parentAccmap.values()){
        parentIds.add(acc.parentId);
    }
    
    map<Id,Set<String>> parentPrMap = new map<Id,Set<String>>();
    list<Contact> prParentlist = [select ID,Email,Name,AccountId, Account.recordtypeId from Contact where AccountId IN:parentIDs and Account.recordtypeId='012600000005J5I']; //add Customer record type Id here.
    for(Contact pr:prParentlist){
        if(parentPrMap.get(pr.AccountId) == null){
            parentPrMap.put(pr.AccountId, new Set<String>());
        }
        parentPrMap.get(pr.AccountId).add(pr.email);
    }

    list<Contact> prParentlist2 = [select ID,Email,Name,account.parentid, Account.recordtypeId from Contact where account.parentid in :parentIDs and Account.recordtypeId='012600000005J5I']; //add Customer record type Id here.
    for(Contact pr:prParentlist2){
        if(parentPrMap.get(pr.account.parentid) == null){
            parentPrMap.put(pr.account.parentid, new Set<String>());
        }
        parentPrMap.get(pr.account.parentid).add(pr.email);
    }
    system.debug(parentPrMap);
    
    for(Contact prr:trigger.new){
        if(
            prr.email!=null
            && parentAccmap.containsKey(prr.Accountid)
            && parentPrMap.containsKey(parentAccmap.get(prr.Accountid).ParentId)
        ){
            if(parentPrMap.get(parentAccmap.get(prr.Accountid).ParentId).contains(prr.email)){
                String baseUrl = URL.getSalesforceBaseUrl().toExternalForm()+'/02Z/e?parentId=';
                string errorMsg = '<a style=\'color:1B2BE8\'href="'+baseUrl+ prr.accountid +'"> Please Create a Contact Role  </a>';
                prr.addError('This Contact already exists.'+ errorMsg,false);
            }
        }   
    }
}

I have written a vf page to display error:


<apex:page standardController="Contact" recordSetVar="contacts" tabStyle="Contact" sidebar="false">
<p>Error.</p>
<apex:form >
<apex:pageBlock > <apex:pageMessage summary="This pageMessage will always display." severity="warning" strength="3" /> <apex:pageMessages />
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!save}"/>
</apex:pageBlockButtons>
<apex:pageBlockTable value="{!contacts}" var="con">
<apex:column value="{!con.name}"/>
<apex:column headerValue="Name">
<apex:outputField value="{!con.Email}"/>
<apex:pageMessages id="errorMessage">
</apex:pageMessages>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>

I am new to apex, can some one help me with linking them and displaying the trigger error on vf page.

Thank You
  • December 08, 2014
  • Like
  • 0

Hi,

I have written a trigger to catch duplicate contacts. I am looking forward to display the already existing contact details and the error message on a separate page:

Here is my trigger:

trigger Duplicate1 on Contact (before insert) {
    set<Id> accIds = new set<Id>();

    for(Contact p :trigger.new){
        accIds.add(p.accountId);
    }
    map<Id,account> parentAccmap = new map<Id,account>([select Id,parentId,recordtypeId from account where Id IN :accIds and parentId!=NULL and recordtypeId='012600000005J5J']); //add Site record type Id here.

    set<ID> parentIds = new set<ID>();
    for(Account acc : parentAccmap.values()){
        parentIds.add(acc.parentId);
    }
    
    map<Id,Set<String>> parentPrMap = new map<Id,Set<String>>();
    list<Contact> prParentlist = [select ID,Email,Name,AccountId, Account.recordtypeId,Phone,FirstName, lastName from Contact where AccountId IN:parentIDs and Account.recordtypeId='012600000005J5I']; //add Customer record type Id here.
    for(Contact pr:prParentlist){
        if(parentPrMap.get(pr.AccountId) == null){
            parentPrMap.put(pr.AccountId, new Set<String>());
        }
        parentPrMap.get(pr.AccountId).add(pr.email);
        parentPrMap.get(pr.AccountId).add(pr.phone);
        parentPrMap.get(pr.AccountId).add(pr.firstname);
        parentPrMap.get(pr.AccountId).add(pr.lastname);
    }

list<Contact> prParentlist2 = [select ID,Email,Name,account.parentid, Account.recordtypeId,Phone,FirstName, lastName from Contact where account.parentid in :parentIDs and Account.recordtypeId='012600000005J5J']; //add Customer record type Id here.
    for(Contact pr:prParentlist2){
        if(parentPrMap.get(pr.account.parentid) == null){
            parentPrMap.put(pr.account.parentid, new Set<String>());
        }
        parentPrMap.get(pr.account.parentid).add(pr.email);
    }
    system.debug(parentPrMap);
    
    for(Contact prr:trigger.new){
        if(
            prr.email!=null
            && parentAccmap.containsKey(prr.Accountid)
            && parentPrMap.containsKey(parentAccmap.get(prr.Accountid).ParentId)
        ){
            if((parentPrMap.get(parentAccmap.get(prr.Accountid).ParentId).contains(prr.email))&&(parentPrMap.get(parentAccmap.get(prr.Accountid).ParentId).contains(prr.phone))&&(parentPrMap.get(parentAccmap.get(prr.Accountid).ParentId).contains(prr.lastname))){
                String baseUrl = URL.getSalesforceBaseUrl().toExternalForm()+'/02Z/e?parentId=';
                string errorMsg = '<a style=\'color:1B2BE8\'href="'+baseUrl+ prr.accountid +'"> Please Create a Contact Role  </a>';
                prr.addError('This Contact already exists.'+ errorMsg,false);
            }
        }   
    }
}

Any help is appreciated.

  • December 03, 2014
  • Like
  • 0
Hi,

How to proceed with the above requirement?

Please let me know some available examples

Thank You
  • December 02, 2014
  • Like
  • 0

Hi,

I have written a trigger to catch duplicates in Contacts.

In tha last step i wish to show the Contact( for whom the duplicate is caught) details that already exists in the system.

Thank You

  • December 02, 2014
  • Like
  • 0
Hi,

I have written a trigger to catch duplicate Contacts. How is it possible to display the details of the already existing contact , whenever a duplicate is caught.
Also i need to display 2 buttons there, One would allow creating the duplicate contact and the other would take the user to Create Coontact Role page.
Any help is appreciated.
Thank You.
  • December 01, 2014
  • Like
  • 0

Hi,

Below is a piece of vf page, how do i include the various record types whilecreating a new lead record

<apex:page standardcontroller="Lead" tabstyle="Lead">
 
 <apex:form >
 
 <apex:sectionheader title="Lead Edit" subtitle="{!if(Lead.Id==null,'New Lead',Lead.Name)}"></apex:sectionheader>
 
 <apex:pageblock mode="edit" id="leadPB" title="Lead Edit">
 
 <apex:pageblockbuttons >
 <apex:commandbutton action="{!save}" value="Save"></apex:commandbutton>
 <!-- If you wish to implement Save & New functionality you will have to write an Apex Extension with your own Save & New Method -->
 <apex:commandbutton action="{!cancel}" value="Cancel"></apex:commandbutton>
 </apex:pageblockbuttons>
 
 <apex:pagemessages ></apex:pagemessages> <!-- displays all message generated by the component -->
 
 <apex:pageblocksection id="LeadInformationPBS" title="Lead Information">
 <!-- Make Owner field editable in system or else you won't be able to edit the Owner -->
 <apex:inputfield value="{!Lead.OwnerId}"></apex:inputfield>
 <apex:inputfield value="{!Lead.Phone}"></apex:inputfield>
 
 <!-- Since we need to group two input fields together we need a pageBlockSectionItem with an Output panel.  We also needed to create a label so we know what field we are entering in -->
 <apex:pageblocksectionitem >
 <apex:outputlabel value="{!$ObjectType.Lead.Fields.FirstName.label}"></apex:outputlabel>
 <apex:outputpanel >
 <apex:inputfield value="{!Lead.Salutation}"></apex:inputfield>
 <apex:inputfield value="{!Lead.FirstName}"></apex:inputfield>
 </apex:outputpanel>
 </apex:pageblocksectionitem>
 <apex:inputfield value="{!Lead.MobilePhone}"></apex:inputfield>
 
 <apex:inputfield value="{!Lead.LastName}"></apex:inputfield>
 <apex:inputfield value="{!Lead.Fax}"></apex:inputfield>
 
 <apex:inputField value="{!Lead.Company}" />
 <apex:inputfield value="{!Lead.Email}" required="true"></apex:inputfield>
 
 <apex:inputfield value="{!Lead.Title}"></apex:inputfield>
 <apex:inputfield value="{!Lead.Website}"></apex:inputfield>
 
 <apex:inputfield value="{!Lead.Leadsource}"></apex:inputfield>
 <apex:inputfield value="{!Lead.Status}"></apex:inputfield>
 
 <!-- <apex:inputField value="{!Lead.Campaign}" />
 Campaign field is not able to be used unless you write your own custom class/method to create a campaign member
 Post explaining this issue: http://boards.developerforce.com/t5/Apex-Code-Development/Cannot-Access-to-Campaign-Field-from-Lead-Object/td-p/161715
 -->
 <apex:inputfield value="{!Lead.Rating}"></apex:inputfield>
 
 <apex:inputfield value="{!Lead.Industry}"></apex:inputfield>
 <apex:inputfield value="{!Lead.NumberOfEmployees}"></apex:inputfield>
 </apex:pageblocksection>
 
 <apex:pageblocksection id="AddressInformationPBS" title="Address Information">
 <apex:inputfield value="{!Lead.Street}"></apex:inputfield>
 <apex:outputtext value=""></apex:outputtext>
 
 <apex:inputfield value="{!Lead.City}"></apex:inputfield>
 <apex:outputtext value=""></apex:outputtext>
 
 <apex:inputfield value="{!Lead.State}"></apex:inputfield>
 <apex:outputtext value=""></apex:outputtext>
 
 <apex:inputfield value="{!Lead.PostalCode}"></apex:inputfield>
 <apex:outputtext value=""></apex:outputtext>
 
 <apex:inputfield value="{!Lead.Country}"></apex:inputfield>
 <apex:outputtext value=""></apex:outputtext> <!-- Don't Really need to implement this extra space, but it's not bad practice -->
 </apex:pageblocksection>
 
 <apex:pageblocksection id="AdditionalInformationPBS" title="Additional Information">
 <apex:inputfield value="{!Lead.ProductInterest__c}"></apex:inputfield>
 <apex:inputfield value="{!Lead.CurrentGenerators__c}"></apex:inputfield>
 
 <apex:inputfield value="{!Lead.SICCode__c}"></apex:inputfield>
 <apex:inputfield value="{!Lead.Primary__c}"></apex:inputfield>
 
 <apex:inputfield value="{!Lead.NumberofLocations__c}"></apex:inputfield>
 </apex:pageblocksection>
 
 <apex:pageblocksection id="DescriptionInformationPBS" title="DescriptionInformation">
 <apex:inputfield value="{!Lead.Description}"></apex:inputfield>
 </apex:pageblocksection>
 
 <apex:pageblocksection id="OptionPBS" title="Lead Information">
 <!-- If you want to have a checkbox to implement whether to use Active Assignment rules you will need to create your own using a custom Apex Extension and method -->
 Here we can place any extra fields or lead options we wish...
 </apex:pageblocksection>
 
 </apex:pageblock>
 
 </apex:form>
 
</apex:page>

  • November 26, 2014
  • Like
  • 0

Hi,

While creating a Duplicate Contact (may be same name) is it possible to show the already existing Contact (of the same name) and then give the option to the end user whether to proceed with creating the same contact again or instead guid them to creating a Contact role?

This sounds very confusing though.

Any help is greatly appreciated.

  • November 24, 2014
  • Like
  • 0
Hi,

I have a piece  of trigger which prevents duplicates on Contacts. I am looking forward to display the existing Contact for which the duplicate was attempted and thus the erro was thrown.
is it possible in this Trigger:

trigger Duplicate1 on Contact (before insert, before update) {
    set<Id> accIds = new set<Id>();

    for(Contact p :trigger.new){
        accIds.add(p.accountId);
    }
    map<Id,account> parentAccmap = new map<Id,account>([select Id,parentId,recordtypeId from account where Id IN :accIds and parentId!=NULL and recordtypeId='012600000005J5J']); //add Site record type Id here.

    set<ID> parentIds = new set<ID>();
    for(Account acc : parentAccmap.values()){
        parentIds.add(acc.parentId);
    }
    
    map<Id,Set<String>> parentPrMap = new map<Id,Set<String>>();
    list<Contact> prParentlist = [select ID,Email,Name,AccountId, Account.recordtypeId,Phone,FirstName, lastName from Contact where AccountId IN:parentIDs and Account.recordtypeId='012600000005J5I']; //add Customer record type Id here.
    for(Contact pr:prParentlist){
        if(parentPrMap.get(pr.AccountId) == null){
            parentPrMap.put(pr.AccountId, new Set<String>());
        }
        parentPrMap.get(pr.AccountId).add(pr.email);
        parentPrMap.get(pr.AccountId).add(pr.phone);
        parentPrMap.get(pr.AccountId).add(pr.firstname);
        parentPrMap.get(pr.AccountId).add(pr.lastname);
    }

list<Contact> prParentlist2 = [select ID,Email,Name,account.parentid, Account.recordtypeId,Phone,FirstName, lastName from Contact where account.parentid in :parentIDs and Account.recordtypeId='012600000005J5J']; //add Customer record type Id here.
    for(Contact pr:prParentlist2){
        if(parentPrMap.get(pr.account.parentid) == null){
            parentPrMap.put(pr.account.parentid, new Set<String>());
        }
        parentPrMap.get(pr.account.parentid).add(pr.email);
    }
    system.debug(parentPrMap);
    
    for(Contact prr:trigger.new){
        if(
            prr.email!=null
            && parentAccmap.containsKey(prr.Accountid)
            && parentPrMap.containsKey(parentAccmap.get(prr.Accountid).ParentId)
        ){
            if((parentPrMap.get(parentAccmap.get(prr.Accountid).ParentId).contains(prr.email))&&(parentPrMap.get(parentAccmap.get(prr.Accountid).ParentId).contains(prr.phone))&&(parentPrMap.get(parentAccmap.get(prr.Accountid).ParentId).contains(prr.lastname))){
                String baseUrl = URL.getSalesforceBaseUrl().toExternalForm()+'/02Z/e?parentId=';
                string errorMsg = '<a style=\'color:1B2BE8\'href="'+baseUrl+ prr.accountid +'"> Please Create a Contact Role  </a>';
                prr.addError('This Contact already exists.'+ errorMsg,false);
            }
        }   
    }
}
 
  • November 05, 2014
  • Like
  • 0

Hi, 
There are two objects named Opportunity and Equipment. They are related using a Junction object named "Opportunity_Equipment__c".

Whenever there is an Equipment with status as "Pending Sale" and the related Opportunity Stagename is "Closed Lost" or Closed Abandoned", i need to delete the equipment.


trigger cascadeJunctionDelete on Opportunity_Equipment__c (after update) {

    List<Opportunity> oppList = new List<Opportunity>();

    List<Equipment__c> eqList = new List<Equipment__c>();

    for(Opportunity_Equipment__c ed : Trigger.old) {


if((Opportunity.StageName == 'Closed Lost' ||  Opportunity.StageName == 'Closed-Abandoned') && ( Equipment__c.Status__c == 'Pending Sales') ) {
        oppList.add(new Opportunity(id=ed.Opportunity__c));


        eqList.add(new Equipment__c(id=ed.Equipment__c)); }  

    }


    
    if(eqList.size() > 0) {

        delete eqList;

    }

}

But am geeting an error while saving this : 
Error: Compile Error: Comparison arguments must be compatible types: Schema.SObjectField, String at line 10 column 5
i.e. at the highlighted line

  • October 28, 2014
  • Like
  • 0

Hi,

There are 2 objects named A and B. These two object are connected through a Junction Object C.

A is the master of the Master Detail relation ship between A and C.

B and C are connected using a lookup relationship.
If i need to delete a record of object B based on certain condition of object A.

Then on which object do i need to write the trigger.

If there are examples for this sort of an application. Please suggest.

Any insight is appreciated.

Thank you.

  • October 28, 2014
  • Like
  • 0
Hi,

I have written a Trigger where in i am Preventing duplicate Contact on a Child Account when Same contact appears on the Parent account.

trigger Duplicate on Contact (before insert , before update) {

        set<Id> accIds = new set<Id>();
    set<Id> parentIds = new set<Id>();
    
     for(Contact p :trigger.new){
        accIds.add(p.accountId);
}
map<Id,account> parentAccmap = new map<Id,account>([select Id,parentId,recordtypeId from account where Id IN :accIds and parentId!=NULL and recordtypeId='012600000005J5J']); //add Site record type Id here.
    for(account a:parentAccmap.values()){
        parentIds.add(a.parentId);
        }
        map<Id,Contact> parentPrMap = new map<Id,Contact>();
    list<Contact> prParentlist = [select ID,Email,AccountId, Account.recordtypeId from Contact where AccountId IN:parentIds and Account.recordtypeId='012600000005J5I']; //add Customer record type Id here.
    for(Contact pr:prParentlist){
        parentPrMap.put(pr.AccountId, pr);
        }
        for(Contact prr:trigger.new){
        if(prr.email!=null && parentAccmap.containsKey(prr.Accountid) && parentPrMap.containsKey(parentAccmap.get(prr.Accountid).ParentId)){
            if(prr.email == parentPrMap.get(parentAccmap.get(prr.Accountid).ParentId).email){
            String baseUrl = URL.getSalesforceBaseUrl().toExternalForm()+'/02Z/e?parentId=';
string errorMsg = '<a style=\'color:1B2BE8\'href="'+baseUrl+ prr.accountid +'"> Please Create a Contact Role  </a>';
                prr.addError('This Contact already exists.'+ errorMsg,false);
            }
        }
    }
}

Can some one help me with logic or modification to the above trigger so that if that contact is present on any of the Child Accounts of the Parent account, error should be thrown.
  • October 21, 2014
  • Like
  • 0
Hi,

Need to write a trigger such that if a Contact already exists ( based on email, phone or name) on the Parent Account or any of the Parents' Child accounts, then if a user tries to Create a Contact, an error should be thrown.

This trigger should be Account based and not Org. 


Lets say a Contact is created on Account 'B'. Account 'A' is the parent for account B. and if i try to create same contact on Account 'C' ( another Child of Account 'A'), error should be thrown.

or also if the Contact exists on Parent and if we try to create  a duplicate on any of its Child, even then an error should be thrown.

I had written a trigger but that worked only on a single account.

Thank You.
  • October 21, 2014
  • Like
  • 0

Hi,

Need to write a trigger such that if a Contact already exists ( based on email, phone or name) on the Parent Account or any of the Parents' Child accounts, then if a user tries to Create a Contact, an error should be thrown.

This trigger should be Account based and not Org. 

Thank You.

  • October 20, 2014
  • Like
  • 0
Hi,

Need to override the delete button on Account object such that the user is not able to edit the Account record if it has any Opportunity ot Service Agreement or Equipment record attached to it.
I have got two record types in Accounts named Customer Account and Sit Account. One should not not be able to delet the Customer Account if the Site Account attacjed to it has any Service Agreement or Equipment or Opportunity attached to it.


  • May 26, 2014
  • Like
  • 1
Hi,  

Please help me writing a soql query in Workbench  to list the opportunities whose status was first rejected and then approved.
I think the query would be on ProcessInstance object.
  • April 01, 2014
  • Like
  • 1
Hi,
There is a lookup relationship on Lead to a Custom Object "Technician".
I am trying to get the Created date of the latest Lead created on the related Technican Record.
I am writing a trigger on Lead (after insert),

trigger LeadDate on Lead (after insert) {

Set<Id> techIds = new Set<Id>();

for (Lead lead : Trigger.new) {
    techIds.add(lead.Technician__c);
}

techIds.remove(null);

if (!techIds.isEmpty()) {
    List<Technician__c> techsToUpdate = new List<Technician__c>();

    for (Technician__c tech : [
        select LatestLeadDate__c,
            (
                select CreatedDate
                from Lead__r
                order by CreatedDate asc
                limit 1
            )
        from Technician__c
        where Id in :techIds
    ]) {
        if (!tech.Lead__r.isEmpty()) {
            if (tech.LatestLeadDate__c != tech.Lead__r.get(0).CreatedDate) {
                tech.LatestLeadDate__c = tech.Lead__r.get(0).CreatedDate;
                techsToUpdate.add(tech);
            }
        }
    }

    if (!techsToUpdate.isEmpty()) {
        update techsToUpdate;
    }
}

}

Error: Error: Compile Error: Didn't understand relationship 'Lead__r' in FROM part of query call. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names. at line 14 column 31

Thank You.
  • April 02, 2015
  • Like
  • 0

Hi,

There is a lookup relationship on Lead to a Custom Object "Technician".

I am trying to get the Created date of the latest Lead created on the related Technican Record.

I am writing a trigger on Lead (after insert), can some one help me with the logic of getting the related techcian id and populate the Created date on technician.

Thank You.

  • April 01, 2015
  • Like
  • 0
Hi,

trigger send_notification on Quote (after update) {

  Quote inquery = trigger.new[0]; 
  Quote.email__c = 'Gaurav.Raj@fs.utc.com';
  String[] toAddresses = new String[] {inquery.email__c}; 
 
  Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();

  //mail.setTargetObjectId(inquery.OwnerID);
  mail.setSenderDisplayName('Salesforce Support');
  mail.setUseSignature(false);
  mail.setBccSender(false);
  mail.setSaveAsActivity(false);

 if (Trigger.isUpdate) { 
    if(inquery.XYZ__c == 'True') {
          EmailTemplate et=[Select id from EmailTemplate where ID=:'00X6000000126rL'];
          mail.setTemplateId(et.id);
          Messaging.SendEmailResult [] r = 
    Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail});   
      } 
      }
      }

it throws an error : 
Error: Compile Error: Expression cannot be assigned at line -1 column -1
 
  • December 17, 2014
  • Like
  • 0
Hi,

How to proceed with the above requirement?

Please let me know some available examples

Thank You
  • December 02, 2014
  • Like
  • 0

Hi,

I have written a trigger to catch duplicates in Contacts.

In tha last step i wish to show the Contact( for whom the duplicate is caught) details that already exists in the system.

Thank You

  • December 02, 2014
  • Like
  • 0
Hi,

I have written a trigger to catch duplicate Contacts. How is it possible to display the details of the already existing contact , whenever a duplicate is caught.
Also i need to display 2 buttons there, One would allow creating the duplicate contact and the other would take the user to Create Coontact Role page.
Any help is appreciated.
Thank You.
  • December 01, 2014
  • Like
  • 0

Hi,

While creating a Duplicate Contact (may be same name) is it possible to show the already existing Contact (of the same name) and then give the option to the end user whether to proceed with creating the same contact again or instead guid them to creating a Contact role?

This sounds very confusing though.

Any help is greatly appreciated.

  • November 24, 2014
  • Like
  • 0

Hi, 
There are two objects named Opportunity and Equipment. They are related using a Junction object named "Opportunity_Equipment__c".

Whenever there is an Equipment with status as "Pending Sale" and the related Opportunity Stagename is "Closed Lost" or Closed Abandoned", i need to delete the equipment.


trigger cascadeJunctionDelete on Opportunity_Equipment__c (after update) {

    List<Opportunity> oppList = new List<Opportunity>();

    List<Equipment__c> eqList = new List<Equipment__c>();

    for(Opportunity_Equipment__c ed : Trigger.old) {


if((Opportunity.StageName == 'Closed Lost' ||  Opportunity.StageName == 'Closed-Abandoned') && ( Equipment__c.Status__c == 'Pending Sales') ) {
        oppList.add(new Opportunity(id=ed.Opportunity__c));


        eqList.add(new Equipment__c(id=ed.Equipment__c)); }  

    }


    
    if(eqList.size() > 0) {

        delete eqList;

    }

}

But am geeting an error while saving this : 
Error: Compile Error: Comparison arguments must be compatible types: Schema.SObjectField, String at line 10 column 5
i.e. at the highlighted line

  • October 28, 2014
  • Like
  • 0

Hi,

There are 2 objects named A and B. These two object are connected through a Junction Object C.

A is the master of the Master Detail relation ship between A and C.

B and C are connected using a lookup relationship.
If i need to delete a record of object B based on certain condition of object A.

Then on which object do i need to write the trigger.

If there are examples for this sort of an application. Please suggest.

Any insight is appreciated.

Thank you.

  • October 28, 2014
  • Like
  • 0
Hi,

I have written a Trigger where in i am Preventing duplicate Contact on a Child Account when Same contact appears on the Parent account.

trigger Duplicate on Contact (before insert , before update) {

        set<Id> accIds = new set<Id>();
    set<Id> parentIds = new set<Id>();
    
     for(Contact p :trigger.new){
        accIds.add(p.accountId);
}
map<Id,account> parentAccmap = new map<Id,account>([select Id,parentId,recordtypeId from account where Id IN :accIds and parentId!=NULL and recordtypeId='012600000005J5J']); //add Site record type Id here.
    for(account a:parentAccmap.values()){
        parentIds.add(a.parentId);
        }
        map<Id,Contact> parentPrMap = new map<Id,Contact>();
    list<Contact> prParentlist = [select ID,Email,AccountId, Account.recordtypeId from Contact where AccountId IN:parentIds and Account.recordtypeId='012600000005J5I']; //add Customer record type Id here.
    for(Contact pr:prParentlist){
        parentPrMap.put(pr.AccountId, pr);
        }
        for(Contact prr:trigger.new){
        if(prr.email!=null && parentAccmap.containsKey(prr.Accountid) && parentPrMap.containsKey(parentAccmap.get(prr.Accountid).ParentId)){
            if(prr.email == parentPrMap.get(parentAccmap.get(prr.Accountid).ParentId).email){
            String baseUrl = URL.getSalesforceBaseUrl().toExternalForm()+'/02Z/e?parentId=';
string errorMsg = '<a style=\'color:1B2BE8\'href="'+baseUrl+ prr.accountid +'"> Please Create a Contact Role  </a>';
                prr.addError('This Contact already exists.'+ errorMsg,false);
            }
        }
    }
}

Can some one help me with logic or modification to the above trigger so that if that contact is present on any of the Child Accounts of the Parent account, error should be thrown.
  • October 21, 2014
  • Like
  • 0