• Kiran Marketing
  • NEWBIE
  • 30 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 7
    Questions
  • 23
    Replies
Senario - I have created a button on Contact which when clicked it redirects to Lead page with prepulated fields like company name, address and so on. It has two custom fields one lookup which alows to choose a user who this new lead would be refered to and othe a field which stores the refered by user name. I got this part now the tricky part is i need to write a trigger as when its clicked on saved button the new lead owner should be saved on the refered to user not on the current user. By default lead owner is stored on current user name. Hence i decided to write a trigger before insert and one after insert which sends a email alert to the new lead owner to which this is refered to or created for. Code looks like missing quite a few things here. Any help would be highly appreciated.
public class LeadTriggerHelperClass {
public static void isBeforeInsert(List<Lead> LeaList)
{Lead Lea = New Lead();
 
    If(Lea.RecordTypeid == '01228000000YtCD')
    {
      Lea.OwnerId = Lea.Reffered_To__c;
    	Insert Lea;
    }
}

public static void isAfterInsert(Lead LeaList)
{
    Lead EmailLead = [SELECT id FROM Lead WHERE id = :LeaList.Id];
  String emailMessage ='A New Lead '
             +'Has been Referred '
             +'By a Sales Representative.' 
             +' For Account'+ EmailLead.Company 
             +' Requirement of ' 
             + EmailLead.Description +
             ' Lead Number'
             + EmailLead.ID 
             +' records were not updated successfully.';
        
        Messaging.SingleEmailMessage mail = 
              new Messaging.SingleEmailMessage();
        String[] toAddresses =new String[] {EmailLead.createdBy.email};
        mail.setToAddresses(toAddresses);
        mail.setReplyTo('noreply@salesforce.com');
        mail.setSenderDisplayName('Lead Created');
        mail.setSubject('Lead Created');
        mail.setPlainTextBody(emailMessage);
        mail.setHtmlBody(emailMessage);
        Messaging.sendEmail(new Messaging.SingleEmailMessage[] 
                           { mail });
  
}
 }

 
I am prepopulating certain values in a standard page and i have created a lookup / formula field on user object where the present user id or account owner id should prepopulated. Not sure for some reason when i am creating a lookup or formula field on user its not getting a hyperlink its giving values but not hyperlinks like owner id when u click your redirected to the user record. I need this as i need to pull reports based on it.

Created formula field (Text) also tried with look up and with User.Id and, user name. Below line shows values but not as hyperlinks to the User Record.

={$User.FirstName + " "+ " " +$User.LastName}

={$User.Id}

Any help would be higly appreciated.
I have a requirement where I need to create a button on lead page when clicked it should redirect to Contact page with prepopulated values like  Lead Company Name - Account Name, Lead Phone - Contact Phone and so on.(standard pages) dont want to create a VF Page. Any suggestions would be appreciated.
Here i have hard coded few things as my initial requirement i just wanted to create a Work Record (Bug Type) in Agile Accelerator when a Case is created. I am able to do so with the below code however not able to attach case and bug. Please find below class code and method.Any help would be highly appreciated.
public class CaseTriggerHelperClass {
    public static void isAfterInsert(Map<Id,case> casemap)
      {
       Id RecordTypeId1 = '01228000000YbH3';
   
    for(Id I : casemap.keyset()){              
         agf__ADM_Work__c aw = new agf__ADM_Work__c();         
         aw.RecordTypeId = RecordTypeId1;
         aw.agf__Subject__c = casemap.get(I).Subject;
         aw.agf__Details_and_Steps_to_Reproduce__c = casemap.get(I).Description;
         aw.agf__Product_Tag__c = 'a0f28000000DAywAAG';
         aw.agf__Found_in_Build__c = 'a0E28000001hCTk';
         aw.agf__Impact__c = 'a0X28000000Hcjf';
         aw.agf__Frequency__c = 'a0T28000000LpJj';
         aw.agf__Priority__c = casemap.get(I).Priority;
         aw.agf__Type__c = '00N28000003qlBQ';
        insert aw;
        
      }
          
   }

}
trigger Link2Agile1 on Case (before Insert, after insert, before update) {

      if(trigger.isAfter && Trigger.isinsert)
      {
              CaseTriggerHelperClass.isAfterInsert(trigger.newmap);
      }
Where in Agile Accelerator It Should Show

 
I have a requirement where one of the user should not be alloowed to insert more than 100K opportunies however i am getting error when i am trying to accomplish the task with below code.

Error - Invalid Data.
Review all error messages below to correct your data.
Apex trigger OpportunityTrigger caused an unexpected exception, contact your administrator: OpportunityTrigger: execution of BeforeInsert caused by: System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, OpportunityTrigger: maximum trigger depth exceeded Opportunity trigger event BeforeInsert for [new] Opportunity trigger event BeforeInsert for [new] Opportunity trigger event BeforeInsert for [new] Opportunity trigger event BeforeInsert for [new] Opportunity trigger event BeforeInsert for [new] O: []: Class.OpportunityTriggerHelperClass.isbeforeinsert: line 29, column 1
 
public class OpportunityTriggerHelperClass {
    
      Public Static Void isbeforeinsert(List<opportunity> OppList)
    {
     User CurrentUs =[Select name,username From User Where Username=:'kiranmarketing16-cltra@gmail.com']; 
String StruserName = CurrentUs.Username;
        List<Opportunity> InvalidOppList = New List<Opportunity>();
        List<Opportunity> validOppList = New List<Opportunity>();
        for(Opportunity Opp : OppList)
           {
              If(null!=StruserName && StruserName.equals('kiranmarketing16-cltra@gmail.com'))
              {
                               If(Opp.Amount > 1000)
                  {
                     InvalidOppList.add(new opportunity(Name=Opp.Name,CloseDate=Opp.CloseDate,
                                StageName=Opp.StageName, Amount=Opp.Amount) );
                      System.debug(InvalidoppList);
                      System.debug('This is true');
       Opp.Amount.addError('You have no previlages to add this opportunity because amount is greated that 100K');
                      }   
       validOppList.add(new opportunity(Name=Opp.Name,CloseDate=Opp.CloseDate,
                                        StageName=Opp.StageName, Amount=Opp.Amount));
            }
                  
             }  
               
      Insert ValidOpplist;

    }
  
}

 
Sandbox: Developer script exception from (org Name) : ECC_UpdateOrderStatus : ECC_hug_UpdateOrderStatus: execution of BeforeUpdate caused by: System.ListException: List index out of bounds: 2120 Class.ECC_hug_UpdateOrderStatusHelper.UpdateOr

Here the class and the trigger are from the appexhcange product we installed. Its a ecommerce app.
I have 3 Objects and i have a senario where i have to write a trigger to insert records in 3 objects, however if the 3 object record fails to insert the earlier 2 inserted record should get deleted. help is highly appreciated.
I have a requirement where I need to create a button on lead page when clicked it should redirect to Contact page with prepopulated values like  Lead Company Name - Account Name, Lead Phone - Contact Phone and so on.(standard pages) dont want to create a VF Page. Any suggestions would be appreciated.
Senario - I have created a button on Contact which when clicked it redirects to Lead page with prepulated fields like company name, address and so on. It has two custom fields one lookup which alows to choose a user who this new lead would be refered to and othe a field which stores the refered by user name. I got this part now the tricky part is i need to write a trigger as when its clicked on saved button the new lead owner should be saved on the refered to user not on the current user. By default lead owner is stored on current user name. Hence i decided to write a trigger before insert and one after insert which sends a email alert to the new lead owner to which this is refered to or created for. Code looks like missing quite a few things here. Any help would be highly appreciated.
public class LeadTriggerHelperClass {
public static void isBeforeInsert(List<Lead> LeaList)
{Lead Lea = New Lead();
 
    If(Lea.RecordTypeid == '01228000000YtCD')
    {
      Lea.OwnerId = Lea.Reffered_To__c;
    	Insert Lea;
    }
}

public static void isAfterInsert(Lead LeaList)
{
    Lead EmailLead = [SELECT id FROM Lead WHERE id = :LeaList.Id];
  String emailMessage ='A New Lead '
             +'Has been Referred '
             +'By a Sales Representative.' 
             +' For Account'+ EmailLead.Company 
             +' Requirement of ' 
             + EmailLead.Description +
             ' Lead Number'
             + EmailLead.ID 
             +' records were not updated successfully.';
        
        Messaging.SingleEmailMessage mail = 
              new Messaging.SingleEmailMessage();
        String[] toAddresses =new String[] {EmailLead.createdBy.email};
        mail.setToAddresses(toAddresses);
        mail.setReplyTo('noreply@salesforce.com');
        mail.setSenderDisplayName('Lead Created');
        mail.setSubject('Lead Created');
        mail.setPlainTextBody(emailMessage);
        mail.setHtmlBody(emailMessage);
        Messaging.sendEmail(new Messaging.SingleEmailMessage[] 
                           { mail });
  
}
 }

 
I am prepopulating certain values in a standard page and i have created a lookup / formula field on user object where the present user id or account owner id should prepopulated. Not sure for some reason when i am creating a lookup or formula field on user its not getting a hyperlink its giving values but not hyperlinks like owner id when u click your redirected to the user record. I need this as i need to pull reports based on it.

Created formula field (Text) also tried with look up and with User.Id and, user name. Below line shows values but not as hyperlinks to the User Record.

={$User.FirstName + " "+ " " +$User.LastName}

={$User.Id}

Any help would be higly appreciated.
I have a requirement where I need to create a button on lead page when clicked it should redirect to Contact page with prepopulated values like  Lead Company Name - Account Name, Lead Phone - Contact Phone and so on.(standard pages) dont want to create a VF Page. Any suggestions would be appreciated.
Here i have hard coded few things as my initial requirement i just wanted to create a Work Record (Bug Type) in Agile Accelerator when a Case is created. I am able to do so with the below code however not able to attach case and bug. Please find below class code and method.Any help would be highly appreciated.
public class CaseTriggerHelperClass {
    public static void isAfterInsert(Map<Id,case> casemap)
      {
       Id RecordTypeId1 = '01228000000YbH3';
   
    for(Id I : casemap.keyset()){              
         agf__ADM_Work__c aw = new agf__ADM_Work__c();         
         aw.RecordTypeId = RecordTypeId1;
         aw.agf__Subject__c = casemap.get(I).Subject;
         aw.agf__Details_and_Steps_to_Reproduce__c = casemap.get(I).Description;
         aw.agf__Product_Tag__c = 'a0f28000000DAywAAG';
         aw.agf__Found_in_Build__c = 'a0E28000001hCTk';
         aw.agf__Impact__c = 'a0X28000000Hcjf';
         aw.agf__Frequency__c = 'a0T28000000LpJj';
         aw.agf__Priority__c = casemap.get(I).Priority;
         aw.agf__Type__c = '00N28000003qlBQ';
        insert aw;
        
      }
          
   }

}
trigger Link2Agile1 on Case (before Insert, after insert, before update) {

      if(trigger.isAfter && Trigger.isinsert)
      {
              CaseTriggerHelperClass.isAfterInsert(trigger.newmap);
      }
Where in Agile Accelerator It Should Show

 
I have a requirement where one of the user should not be alloowed to insert more than 100K opportunies however i am getting error when i am trying to accomplish the task with below code.

Error - Invalid Data.
Review all error messages below to correct your data.
Apex trigger OpportunityTrigger caused an unexpected exception, contact your administrator: OpportunityTrigger: execution of BeforeInsert caused by: System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, OpportunityTrigger: maximum trigger depth exceeded Opportunity trigger event BeforeInsert for [new] Opportunity trigger event BeforeInsert for [new] Opportunity trigger event BeforeInsert for [new] Opportunity trigger event BeforeInsert for [new] Opportunity trigger event BeforeInsert for [new] O: []: Class.OpportunityTriggerHelperClass.isbeforeinsert: line 29, column 1
 
public class OpportunityTriggerHelperClass {
    
      Public Static Void isbeforeinsert(List<opportunity> OppList)
    {
     User CurrentUs =[Select name,username From User Where Username=:'kiranmarketing16-cltra@gmail.com']; 
String StruserName = CurrentUs.Username;
        List<Opportunity> InvalidOppList = New List<Opportunity>();
        List<Opportunity> validOppList = New List<Opportunity>();
        for(Opportunity Opp : OppList)
           {
              If(null!=StruserName && StruserName.equals('kiranmarketing16-cltra@gmail.com'))
              {
                               If(Opp.Amount > 1000)
                  {
                     InvalidOppList.add(new opportunity(Name=Opp.Name,CloseDate=Opp.CloseDate,
                                StageName=Opp.StageName, Amount=Opp.Amount) );
                      System.debug(InvalidoppList);
                      System.debug('This is true');
       Opp.Amount.addError('You have no previlages to add this opportunity because amount is greated that 100K');
                      }   
       validOppList.add(new opportunity(Name=Opp.Name,CloseDate=Opp.CloseDate,
                                        StageName=Opp.StageName, Amount=Opp.Amount));
            }
                  
             }  
               
      Insert ValidOpplist;

    }
  
}