• Nichole Smith
  • NEWBIE
  • 40 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 7
    Replies
I am trying to write a trigger to compare the area code from the lead phone and the Area Code name, pull the Parent Market from the Area Code and populate it on a field in the Lead upon creation. The relationship between the 3 objects are: 
Area_Code__c (child Object of Market__c)
Market__c(Custom Object with master-detail to Area_Code)
Lead(Lookup relationship to Market__c called Lead_Market__c)
I created a formula field on the lead object to pull the area code out of the phone number on lead and it is called Area_Code__c.
I have created this Trigger and it saves but and I am not getting any errors but it is not populating the Lead_Market__c field either. According to the debug logs the problem seems to be in the last for loop called  LeadNameLoop. Does anyone see anything wrong with this?
Trigger AreaCode on Lead (before insert) {

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

for(Lead LeadNameLoop : trigger.New)
{
    InitialLeadName.add(LeadNameLoop.Area_Code__c);
}
Map <String, Area_Code__c> matchingAreaCodeMap = new Map <String, Area_Code__c> ();

for (Area_Code__c Record : [Select Id, Name, Market__c From Area_Code__c Where Name IN :InitialLeadName])
{
    matchingAreaCodeMap.put(Record.Market__c, record);
}

List <Lead> FinalLeadList = new List <Lead> ();

    for(Lead LeadNameLoop : trigger.New)
{
    if (matchingAreaCodeMap.get(LeadNameLoop.Name) != null)
    {
          LeadNameLoop.Lead_Market__c = matchingAreaCodeMap.get(LeadNameLoop.Area_Code__c).Market__c;
         FinalLeadList.add(LeadNameLoop);
    }
} 
upsert FinalLeadList;
}
I have created a Task Trigger to count the number of Calls related to an Account from all of the related record (Contacts, Opportunities) and used 2 fields on the Account (Activity Count, AS Activity Count) to store the count in depending on the Rep who was making the call. The issue I am having though is that the Account part is working great but the Contact and Opportunity is recieving an error stating that the Account Id was recieved without querying the requested field. Listed below is my trigger. What am I doing wrong?
trigger Activity_Count on Task (before insert, before update){

    Set<Id> accIds = new Set<Id>();
   Map<Id,Account> accMap = new Map<Id,Account>();
    Map<Id,Task> conMap = new Map<Id,Task>();
    Map<Id,Task> oppMap = new Map<Id, Task>();
     List<Account> updateAccountList = new List<Account>();  
   List<Contact> udpateContactList = new List<Contact>();
    List<Opportunity> updateOppList = new List<Opportunity>();
    String accPrefix = Account.sObjectType.getDescribe().getKeyPrefix();
    String contactPrefix = Contact.sObjectType.getDescribe().getKeyPrefix();
    String oppPrefix= Opportunity.sObjectType.getDescribe().getKeyPrefix();
 
        
    for (Task t :  Trigger.new) {
     
     String str = t.whatId;
       String contactstr = t.WhoId;
        
          if(t.WhoId!=null && t.Subject.contains('Call') && contactstr.startsWith(contactPrefix) && t.status =='Completed'  && t.Counted__c != True)      //Task belongs to the Contact
          {
                        conMap.put(t.whoId, t);
              			   t.Counted__c=true;
            }
        if(t.WhatId!=null && t.Subject.contains('Call') && str.startsWith(accPrefix) && t.status =='Completed' && t.Counted__c !=True)     // Task belongs to Account with AS Rep Owner
          {
            accIds.add(t.whatId);
           t.Counted__c=true;
          }
         if(t.WhatId != null && t.Subject.contains('Call') && str.startsWith(oppPrefix) && t.status =='Completed' && t.Counted__c != True)     //Task belongs to Opportunity
        {
            
                  oppMap.put(t.whatId, t);
            		   t.Counted__c=true;
   		 } 
    
    }
    try{
String ProfileId = userinfo.getProfileId();
if(accIds.size() > 0){ 
              accMap = new Map<Id, Account> ([SELECT Id, 
                                              Activity_Count__c,
                                              AS_Activity_Count__c
                                           FROM Account WHERE Id in :accIds]);
           updateAccountList = accMap.values();
         
               for(Account acc : updateAccountList){
                     if(acc.AS_Activity_Count__c != null){
                           acc.AS_Activity_Count__c =  acc.AS_Activity_Count__c +1;
                        }
                   If(ProfileId =='00e30000001wVmqAAE'){
                          acc.AS_Activity_Count__c =1; 
                     }
                   if(acc.Activity_Count__c != null && ProfileId =='00e30000001wWXJAA2'){
                        acc.Activity_Count__c =  acc.Activity_Count__c +1;
                   }
                  If(ProfileId=='00e30000001wWXJ'){
                         acc.Activity_Count__c =1;
                   }
               }
         update updateAccountList;
        }
If(conMap.size()>0){ //Updating Accounts when Task is logged on Contact
                
          udpateContactList = [Select Id, AccountId from Contact where Id IN: conMap.keySet()];
          
          for(Contact con : udpateContactList){
				  If(con.Account.AS_Activity_Count__c!=null && ProfileId =='00e30000001wVmq'){
                          con.Account.AS_Activity_Count__c = con.Account.AS_Activity_Count__c+1; 
                     }
                If(ProfileId =='00e30000001wVmq'){
                         con.Account.AS_Activity_Count__c =1; 
                     }
                   if(con.Account.Activity_Count__c != null && ProfileId =='00e30000001wWXJ'){
                        con.Account.Activity_Count__c = con.Account.Activity_Count__c +1;
                   }
                  If(ProfileId=='00e30000001wWXJ'){
                         con.Account.Activity_Count__c =1;
                   }
             }
         update udpateContactList;
        }
      
    If(oppMap.size() >0){ //Updating Accounts when call is logged on Opportunity
      updateOppList = [Select Id, AccountId from Opportunity where Id IN: oppMap.keySet()];
         for(Opportunity opps : updateOppList){  
                   If(opps.Account.AS_Activity_Count__c!=null && ProfileId =='00e30000001wVmq'){
                         opps.Account.AS_Activity_Count__c =  opps.Account.AS_Activity_Count__c +1; 
                     }
                 If(ProfileId =='00e30000001wVmq'){
                         opps.Account.AS_Activity_Count__c =1; 
                     }
                   if( ProfileId =='00e30000001wWXJ' && opps.Account.Activity_Count__c != null ){
                        opps.Account.Activity_Count__c =  opps.Account.Activity_Count__c +1;
                   }
                  If(ProfileId=='00e30000001wWXJ'){
                         opps.Account.Activity_Count__c =1;
                   }
             }
         update updateOppList;
    
             }
    }
  catch(Exception e){
        System.debug('Exception in Trigger:Activity_Count'  + e.getMessage());
    }
    
}
I have a custom object that we record calls in. Once a new call is created the phone label field, .IBP__PhoneLabel__c, is filled in with the unique external id of an Account and the name of the call as such: 452226- Outbound Call 3/18/2016. I created a trigger to pull the unqiue id from this phone label, 452226, and use that to match the unique id field on the Account, SPID__c, and once there was a match I was asscoiate the call record to the Account via the lookup field called, Account__c. Here is my trigger. There is no errors but the account isnt being populated. What am I missing?

trigger CallMatch on IBP__Ifbyphone_Call__c (before insert) {
 Map<String,id> SPIDS = new Map<String,id>();
    for(Account spid: [select id,SPID__c from Account]){
       SPIDS.put(spid.SPID__C,spid.id);
    }
    
    for(IBP__Ifbyphone_Call__c dt :trigger.New){
      if(dt.IBP__PhoneLabel__c != null){
       string spid1 = dt.IBP__PhoneLabel__c.substring(dt.IBP__PhoneLabel__c.indexOf('[')+1, dt.IBP__PhoneLabel__c.indexOf('-'));
        if(SPIDS.containsKey(spid1)){
            dt.Account__c = SPIDS.get(spid1);
        }
      }
        else{
            dt.Account__c = null;
        }
    }
}
We have a use case were we need to have a custom button that would clone a custom object and all of its related records. I have created the button and it works great as the system administrator because that profile has access to the fields but when I log in as one of the other users I get an error because they dont have access to the fields. For security reasons we dont want to give them access to the fields but we want them to be able to clone the existing record. So what we would need is to have this button run as a system administrator. Is that possible? 

 
We have a custom object called Opportunty_Product__c that is a lookup to an opportunity. What I wanted to get all of the sibling records of the current opportunity product into a visualforce page where I could select one and link it to the current opportunity product. I am new to apex code and have tried to get this done in a class but all I can get in the page is the opportunity product you clicked the visualforce page from. What am I doing wrong?

Here is my Apex Class:
public with sharing class LinkOfferOpportunityProduct {
    public list <Opportunity_Product__c> OppProdList {get;set;}
    public list <Opportunity_Product__c> OppProdId {get;set;}
    public list <Opportunity_Product__c> LOppProds{get;set;}
    public list <Opportunity_Product__c> OppList {get;set;}
    public list <string> OppIds {get; set;}
    public string selectedOppProd {get;set;}
     public string sSelectedDeal {get; set;}
public LinkOfferOpportunityProduct(){
    try {   
     OppProdId = new list<Opportunity_Product__c> ();
     OppIds = new list<string> ();
    selectedOppProd = ApexPages.currentPage().getParameters().get('id');
     
    OppProdID = [SELECT Id,Opportunity__c FROM Opportunity_Product__c
          WHERE Id =: selectedOppProd];
        
        for (Opportunity_Product__c OppProd : OppProdID) {
      OppIds.add(OppProd.Opportunity__c);
    }
        LOppProds = [SELECT id,Final_Deal_Title_Editable__c,Opportunity__c,Member_Price__c,Start_Date__c FROM Opportunity_Product__c 
                     WHERE id =: OppProdId]; 
  }catch (Exception oException){
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.FATAL, oException.getMessage()));
    }     
    }
public PageReference AddlinkedOffer() {
     PageReference OppProdPageRef;
 Opportunity_Product__c SelectedOppProdId= [SELECT
                  Id,Linked_Deal__c            
                 FROM
                    Opportunity_Product__c
                WHERE
                    Id = :LOppProds];
      SelectedOppProdId.Linked_Deal__c= sSelectedDeal;
            try {   
        update SelectedOppProdId;  
        OppProdPageRef = new PageReference('/' + selectedOppProdId);

    } catch (Exception oException){
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.FATAL, oException.getMessage()));
    }  
    return OppProdPageRef;          
  }   
  }


An here is my visualforce page:

<apex:page controller="LinkedOfferOpportunityProduct">
<apex:form >
<apex:pageBlock >
<apex:PageBlockTable value="{!LOppProds}" var="oppprods" > <apex:column headerValue="Deal Title">
<apex:outputText value="{!oppprods.Final_Deal_Title_Editable__c}" />
</apex:column> <apex:column headerValue="Member Price">
<apex:outputText value="{!oppprods.Member_Price__c}" />
</apex:column> <apex:column headerValue="Start Date">
<apex:outputText value="{!oppprods.Start_Date__c}" />
</apex:column>
<apex:column headerValue="Link Offer to Opportunity Product" >
<apex:commandLink action="{!Addlinkedoffer}" value="Select" id="commandLink" >
<apex:param name="nickName" value="{!oppprods.Id}" assignTo="{!sSelectedDeal}"/>
</apex:commandLink>
</apex:column>
</apex:PageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>

 
I am trying to write a trigger to compare the area code from the lead phone and the Area Code name, pull the Parent Market from the Area Code and populate it on a field in the Lead upon creation. The relationship between the 3 objects are: 
Area_Code__c (child Object of Market__c)
Market__c(Custom Object with master-detail to Area_Code)
Lead(Lookup relationship to Market__c called Lead_Market__c)
I created a formula field on the lead object to pull the area code out of the phone number on lead and it is called Area_Code__c.
I have created this Trigger and it saves but and I am not getting any errors but it is not populating the Lead_Market__c field either. According to the debug logs the problem seems to be in the last for loop called  LeadNameLoop. Does anyone see anything wrong with this?
Trigger AreaCode on Lead (before insert) {

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

for(Lead LeadNameLoop : trigger.New)
{
    InitialLeadName.add(LeadNameLoop.Area_Code__c);
}
Map <String, Area_Code__c> matchingAreaCodeMap = new Map <String, Area_Code__c> ();

for (Area_Code__c Record : [Select Id, Name, Market__c From Area_Code__c Where Name IN :InitialLeadName])
{
    matchingAreaCodeMap.put(Record.Market__c, record);
}

List <Lead> FinalLeadList = new List <Lead> ();

    for(Lead LeadNameLoop : trigger.New)
{
    if (matchingAreaCodeMap.get(LeadNameLoop.Name) != null)
    {
          LeadNameLoop.Lead_Market__c = matchingAreaCodeMap.get(LeadNameLoop.Area_Code__c).Market__c;
         FinalLeadList.add(LeadNameLoop);
    }
} 
upsert FinalLeadList;
}
I have created a Task Trigger to count the number of Calls related to an Account from all of the related record (Contacts, Opportunities) and used 2 fields on the Account (Activity Count, AS Activity Count) to store the count in depending on the Rep who was making the call. The issue I am having though is that the Account part is working great but the Contact and Opportunity is recieving an error stating that the Account Id was recieved without querying the requested field. Listed below is my trigger. What am I doing wrong?
trigger Activity_Count on Task (before insert, before update){

    Set<Id> accIds = new Set<Id>();
   Map<Id,Account> accMap = new Map<Id,Account>();
    Map<Id,Task> conMap = new Map<Id,Task>();
    Map<Id,Task> oppMap = new Map<Id, Task>();
     List<Account> updateAccountList = new List<Account>();  
   List<Contact> udpateContactList = new List<Contact>();
    List<Opportunity> updateOppList = new List<Opportunity>();
    String accPrefix = Account.sObjectType.getDescribe().getKeyPrefix();
    String contactPrefix = Contact.sObjectType.getDescribe().getKeyPrefix();
    String oppPrefix= Opportunity.sObjectType.getDescribe().getKeyPrefix();
 
        
    for (Task t :  Trigger.new) {
     
     String str = t.whatId;
       String contactstr = t.WhoId;
        
          if(t.WhoId!=null && t.Subject.contains('Call') && contactstr.startsWith(contactPrefix) && t.status =='Completed'  && t.Counted__c != True)      //Task belongs to the Contact
          {
                        conMap.put(t.whoId, t);
              			   t.Counted__c=true;
            }
        if(t.WhatId!=null && t.Subject.contains('Call') && str.startsWith(accPrefix) && t.status =='Completed' && t.Counted__c !=True)     // Task belongs to Account with AS Rep Owner
          {
            accIds.add(t.whatId);
           t.Counted__c=true;
          }
         if(t.WhatId != null && t.Subject.contains('Call') && str.startsWith(oppPrefix) && t.status =='Completed' && t.Counted__c != True)     //Task belongs to Opportunity
        {
            
                  oppMap.put(t.whatId, t);
            		   t.Counted__c=true;
   		 } 
    
    }
    try{
String ProfileId = userinfo.getProfileId();
if(accIds.size() > 0){ 
              accMap = new Map<Id, Account> ([SELECT Id, 
                                              Activity_Count__c,
                                              AS_Activity_Count__c
                                           FROM Account WHERE Id in :accIds]);
           updateAccountList = accMap.values();
         
               for(Account acc : updateAccountList){
                     if(acc.AS_Activity_Count__c != null){
                           acc.AS_Activity_Count__c =  acc.AS_Activity_Count__c +1;
                        }
                   If(ProfileId =='00e30000001wVmqAAE'){
                          acc.AS_Activity_Count__c =1; 
                     }
                   if(acc.Activity_Count__c != null && ProfileId =='00e30000001wWXJAA2'){
                        acc.Activity_Count__c =  acc.Activity_Count__c +1;
                   }
                  If(ProfileId=='00e30000001wWXJ'){
                         acc.Activity_Count__c =1;
                   }
               }
         update updateAccountList;
        }
If(conMap.size()>0){ //Updating Accounts when Task is logged on Contact
                
          udpateContactList = [Select Id, AccountId from Contact where Id IN: conMap.keySet()];
          
          for(Contact con : udpateContactList){
				  If(con.Account.AS_Activity_Count__c!=null && ProfileId =='00e30000001wVmq'){
                          con.Account.AS_Activity_Count__c = con.Account.AS_Activity_Count__c+1; 
                     }
                If(ProfileId =='00e30000001wVmq'){
                         con.Account.AS_Activity_Count__c =1; 
                     }
                   if(con.Account.Activity_Count__c != null && ProfileId =='00e30000001wWXJ'){
                        con.Account.Activity_Count__c = con.Account.Activity_Count__c +1;
                   }
                  If(ProfileId=='00e30000001wWXJ'){
                         con.Account.Activity_Count__c =1;
                   }
             }
         update udpateContactList;
        }
      
    If(oppMap.size() >0){ //Updating Accounts when call is logged on Opportunity
      updateOppList = [Select Id, AccountId from Opportunity where Id IN: oppMap.keySet()];
         for(Opportunity opps : updateOppList){  
                   If(opps.Account.AS_Activity_Count__c!=null && ProfileId =='00e30000001wVmq'){
                         opps.Account.AS_Activity_Count__c =  opps.Account.AS_Activity_Count__c +1; 
                     }
                 If(ProfileId =='00e30000001wVmq'){
                         opps.Account.AS_Activity_Count__c =1; 
                     }
                   if( ProfileId =='00e30000001wWXJ' && opps.Account.Activity_Count__c != null ){
                        opps.Account.Activity_Count__c =  opps.Account.Activity_Count__c +1;
                   }
                  If(ProfileId=='00e30000001wWXJ'){
                         opps.Account.Activity_Count__c =1;
                   }
             }
         update updateOppList;
    
             }
    }
  catch(Exception e){
        System.debug('Exception in Trigger:Activity_Count'  + e.getMessage());
    }
    
}
I have a custom object that we record calls in. Once a new call is created the phone label field, .IBP__PhoneLabel__c, is filled in with the unique external id of an Account and the name of the call as such: 452226- Outbound Call 3/18/2016. I created a trigger to pull the unqiue id from this phone label, 452226, and use that to match the unique id field on the Account, SPID__c, and once there was a match I was asscoiate the call record to the Account via the lookup field called, Account__c. Here is my trigger. There is no errors but the account isnt being populated. What am I missing?

trigger CallMatch on IBP__Ifbyphone_Call__c (before insert) {
 Map<String,id> SPIDS = new Map<String,id>();
    for(Account spid: [select id,SPID__c from Account]){
       SPIDS.put(spid.SPID__C,spid.id);
    }
    
    for(IBP__Ifbyphone_Call__c dt :trigger.New){
      if(dt.IBP__PhoneLabel__c != null){
       string spid1 = dt.IBP__PhoneLabel__c.substring(dt.IBP__PhoneLabel__c.indexOf('[')+1, dt.IBP__PhoneLabel__c.indexOf('-'));
        if(SPIDS.containsKey(spid1)){
            dt.Account__c = SPIDS.get(spid1);
        }
      }
        else{
            dt.Account__c = null;
        }
    }
}
We have a use case were we need to have a custom button that would clone a custom object and all of its related records. I have created the button and it works great as the system administrator because that profile has access to the fields but when I log in as one of the other users I get an error because they dont have access to the fields. For security reasons we dont want to give them access to the fields but we want them to be able to clone the existing record. So what we would need is to have this button run as a system administrator. Is that possible? 

 
We have a custom object called Opportunty_Product__c that is a lookup to an opportunity. What I wanted to get all of the sibling records of the current opportunity product into a visualforce page where I could select one and link it to the current opportunity product. I am new to apex code and have tried to get this done in a class but all I can get in the page is the opportunity product you clicked the visualforce page from. What am I doing wrong?

Here is my Apex Class:
public with sharing class LinkOfferOpportunityProduct {
    public list <Opportunity_Product__c> OppProdList {get;set;}
    public list <Opportunity_Product__c> OppProdId {get;set;}
    public list <Opportunity_Product__c> LOppProds{get;set;}
    public list <Opportunity_Product__c> OppList {get;set;}
    public list <string> OppIds {get; set;}
    public string selectedOppProd {get;set;}
     public string sSelectedDeal {get; set;}
public LinkOfferOpportunityProduct(){
    try {   
     OppProdId = new list<Opportunity_Product__c> ();
     OppIds = new list<string> ();
    selectedOppProd = ApexPages.currentPage().getParameters().get('id');
     
    OppProdID = [SELECT Id,Opportunity__c FROM Opportunity_Product__c
          WHERE Id =: selectedOppProd];
        
        for (Opportunity_Product__c OppProd : OppProdID) {
      OppIds.add(OppProd.Opportunity__c);
    }
        LOppProds = [SELECT id,Final_Deal_Title_Editable__c,Opportunity__c,Member_Price__c,Start_Date__c FROM Opportunity_Product__c 
                     WHERE id =: OppProdId]; 
  }catch (Exception oException){
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.FATAL, oException.getMessage()));
    }     
    }
public PageReference AddlinkedOffer() {
     PageReference OppProdPageRef;
 Opportunity_Product__c SelectedOppProdId= [SELECT
                  Id,Linked_Deal__c            
                 FROM
                    Opportunity_Product__c
                WHERE
                    Id = :LOppProds];
      SelectedOppProdId.Linked_Deal__c= sSelectedDeal;
            try {   
        update SelectedOppProdId;  
        OppProdPageRef = new PageReference('/' + selectedOppProdId);

    } catch (Exception oException){
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.FATAL, oException.getMessage()));
    }  
    return OppProdPageRef;          
  }   
  }


An here is my visualforce page:

<apex:page controller="LinkedOfferOpportunityProduct">
<apex:form >
<apex:pageBlock >
<apex:PageBlockTable value="{!LOppProds}" var="oppprods" > <apex:column headerValue="Deal Title">
<apex:outputText value="{!oppprods.Final_Deal_Title_Editable__c}" />
</apex:column> <apex:column headerValue="Member Price">
<apex:outputText value="{!oppprods.Member_Price__c}" />
</apex:column> <apex:column headerValue="Start Date">
<apex:outputText value="{!oppprods.Start_Date__c}" />
</apex:column>
<apex:column headerValue="Link Offer to Opportunity Product" >
<apex:commandLink action="{!Addlinkedoffer}" value="Select" id="commandLink" >
<apex:param name="nickName" value="{!oppprods.Id}" assignTo="{!sSelectedDeal}"/>
</apex:commandLink>
</apex:column>
</apex:PageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>