• Khushmeet Kaur
  • NEWBIE
  • 75 Points
  • Member since 2019

  • Chatter
    Feed
  • 2
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 23
    Replies
Good morning all,

I am trying to build a trigger that will create a related custom object  record when an Opportyunity is created or updated.

This is my code so far:
trigger createOpenQuarter on Opportunity (after insert,after update) {
     
    List <Open_Quarter__c> createOpenQuarter = new List <Open_Quarter__c> ();
        
    
        Open_Quarter__c oq = new Open_Quarter__c ();
        Quarter_Number__c qn = new Quarter_Number__c ();
    	Opportunity o = new Opportunity ();
    
         
        oq.Amount_Per_Quarter__c = o.Amount_per_Quarter__c; 
        oq.Close_Date__c = o.CloseDate;
        oq.Name = o.Quarter_Created__c;
        oq.Opportunity_Name__c = o.Name;
        oq.Quarters_Spanned__c = o.Quarters_Spanned__c;
         
        createOpenQuarter.add(oq);
         
    try {
        insert createOpenQuarter;
    } catch (system.Dmlexception e) {
        system.debug (e);
    }
}

I am trying to get this a step at a time. So I just want the first step to work.

The trigger is active in my sandbox so i was hoping that when I created a new Opp or updated an existing one that the trigger would create the custom record but nothing happens.

Can you let me know what I am missing or have done wrong? Once this part works i will work on the next step. Just trying to learn as i go.

I am brand new to coding so i appreciate your patience and any help i can get. I do not get any errors with the obove code, but nothing happens either.

Best regards,
Steve
trigger TaskOnLeadStatusTrigger on Lead (after insert, after update) {
     
    List<Task> taskList = new List<Task>();
    
    // Add a task for each Lead.
    // Iterate over Leads those are inserted recently.
          for (Lead ld : Trigger.New) 
        {
        // Add a task for this lead with selected status and subject = 'Lead status changed'.
        taskList.add(new Task(WhoId = ld.OwnerId, Subject='Lead status changed"'+ld.Status+'". Start the next process')); 
    }
    
    if (taskList.size() > 0) 
        insert taskList;
        
}
Why is it not working, my goal is to create a task on leads with selected status using trigger. with WhoId i am trying to link Ids.
Hi,

I want to create the % of the revenue increase or decrease in the standard report.
For example, I want to compare the opportunity revenue for the current month with the previous month(To store revenue on the opportunity for a current and previous month there are 2 separate fields).

 
I have overriden my standard newContact page with a custom lightning component bundle. The reason i did this is to avoid  standard salesforce fields like account phone getting auto populated when creating a contact through Account related list. 

I utilized force:createRecord event and have resolved almost all of the issues except for only 1 which i am stuck and need to get it resolved.

Problem: The problem is that in my component i am retrieveing accountId and recordTypeID. When i click on an account i ended up on the detail page. Now when i click new contact from account detail related list, it invokes my lightning component which basically fires force:Createrecord event. Since i came from the account detail page, my parent window should be account detail page also but it is not. It basically hovers over to an empty 'Contacts'  tab. This is because the window URL has changed.

Original URL before creating new contact from account detail page:-
https://*.force.com/one/one.app#/sObject/001f400000AdMNOAA3/view

After clicking new contact :-
https://*.force.com/one/one.app#/sObject/Contact/new?recordTypeId=012f4000000DzRj&additionalParams=accid%3D001f400000AdMNO%26

My question is that is there any way i can take the user back to account detail page if he/she closes the modal dialog or click cancel ? Please find my small test code below

ContactComponent.cmp
<aura:component implements="force:lightningQuickAction,lightning:actionOverride,force:hasRecordId,flexipage:availableForAllPageTypes,force:appHostable" access="global">
    <aura:handler name="init" value="{!this}" action="{!c.init}" />
    <aura:attribute name="accid" type="Id" />
    <aura:attribute name="recordTypeId" type="Id" />
</aura:component>

ContactComponentController.js
({
    init : function(component, event, helper) {
        console.log('insideinit');
                var createAcountContactEvent = $A.get("e.force:createRecord");
                console.log('Account ID after action is ' + accId);
                createAcountContactEvent.setParams({
                    "entityApiName": "Contact",
                    "defaultFieldValues": {
                        'Phone' : ''
                    }
                });
                createAcountContactEvent.fire(); 
    }
})
Hi,

I want to create the % of the revenue increase or decrease in the standard report.
For example, I want to compare the opportunity revenue for the current month with the previous month(To store revenue on the opportunity for a current and previous month there are 2 separate fields).

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

    for(contact address : trigger.new)
    {
    if(address.Copy_Address__c ==True)
    {
    address.OtherStreet = address.MailingStreet ; 
    address.OtherCity   = address.MailingCity;
    address.OtherState = address.MailingState;
    address.OtherPostalCode = address.MailingPostalCode;
    address.OtherCountry = address.MailingCountry;    
    }  
        else
    { address.OtherStreet = null ; 
    address.OtherCity   = null;
    address.OtherState = null;
    address.OtherPostalCode = null;
    address.OtherCountry = null;
    }
}
}
What is the key difference between Joined Reports and Custom Report Types?
  • March 30, 2020
  • Like
  • 0
Good morning all,

I am trying to build a trigger that will create a related custom object  record when an Opportyunity is created or updated.

This is my code so far:
trigger createOpenQuarter on Opportunity (after insert,after update) {
     
    List <Open_Quarter__c> createOpenQuarter = new List <Open_Quarter__c> ();
        
    
        Open_Quarter__c oq = new Open_Quarter__c ();
        Quarter_Number__c qn = new Quarter_Number__c ();
    	Opportunity o = new Opportunity ();
    
         
        oq.Amount_Per_Quarter__c = o.Amount_per_Quarter__c; 
        oq.Close_Date__c = o.CloseDate;
        oq.Name = o.Quarter_Created__c;
        oq.Opportunity_Name__c = o.Name;
        oq.Quarters_Spanned__c = o.Quarters_Spanned__c;
         
        createOpenQuarter.add(oq);
         
    try {
        insert createOpenQuarter;
    } catch (system.Dmlexception e) {
        system.debug (e);
    }
}

I am trying to get this a step at a time. So I just want the first step to work.

The trigger is active in my sandbox so i was hoping that when I created a new Opp or updated an existing one that the trigger would create the custom record but nothing happens.

Can you let me know what I am missing or have done wrong? Once this part works i will work on the next step. Just trying to learn as i go.

I am brand new to coding so i appreciate your patience and any help i can get. I do not get any errors with the obove code, but nothing happens either.

Best regards,
Steve
Hi Team,
Requirement: Update Account status from Opportunity based on Contract Expiration Date.
1. Contract expiration date >Today - need to update Status=Active.
2. Suppose we have 10 opportunities to an Account, If any one of the opportunity contract expiration date > Today, need to update Account Status=Active else Expired.
Please advise how can we achieve this requirement?

Thanks,
Lakshmi S.
trigger TaskOnLeadStatusTrigger on Lead (after insert, after update) {
     
    List<Task> taskList = new List<Task>();
    
    // Add a task for each Lead.
    // Iterate over Leads those are inserted recently.
          for (Lead ld : Trigger.New) 
        {
        // Add a task for this lead with selected status and subject = 'Lead status changed'.
        taskList.add(new Task(WhoId = ld.OwnerId, Subject='Lead status changed"'+ld.Status+'". Start the next process')); 
    }
    
    if (taskList.size() > 0) 
        insert taskList;
        
}
Why is it not working, my goal is to create a task on leads with selected status using trigger. with WhoId i am trying to link Ids.
Hi Team,

Requirement: Update Account status from Opportunity based on Contract Expiration Date.
1. Contract expiration date >Today - need to update Status=Active.
2. Suppose we have 10 opportunities to an Account, If any one of the opportunity contract expiration date > Today, need to update Account Status=Active else Expired.
Please advise how can we achieve this requirement?

Thanks,
Lakshmi S.
Hi, I have written a batch class to send email to contact owner with Contact details created by lead conversion. I have tried Test class for the same but it was not running. Can someone help me resolve this.

//Batch Class
global class EmailWithAttachment implements Database.Batchable <sObject>, Database.Stateful{
    public List<Contact> conList {get;set;}
    public String body{get;set;}
    global Database.QueryLocator start(Database.BatchableContext BC) {
        String query = 'SELECT Id, FirstName, LastName, LeadSource, ConvertedDate isConverted FROM Lead';
        //system.debug('aaaaaaa'+query);
        return Database.getQueryLocator(query);
        
    }
    global void execute(Database.BatchableContext BC, Lead[] scope) {
        List<Contact> conList = new List<Contact>();
        for(Lead lead : scope) {
            conList = ([SELECT FirstName, LastName, Email, Phone
                        FROM Contact 
                        WHERE Id IN (SELECT ConvertedContactId FROM Lead)]);
        }
        system.debug('Contacts List'+conList);
        String.join(conList,',');
        messaging.SingleEmailMessage email = new messaging.SingleEmailMessage();
        body = 'Contact Details : ' +conList+ '';
        email.setPlainTextBody(body);
        email.setSubject('Contact Details from Converted Lead');
        email.setToAddresses(new string[]{'maddulasaivineeth@gmail.com'});
        Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});
        //system.debug('Contacts'+conList);
    }
    global void Finish(Database.BatchableContext BC) {
        
    }
}

//Test Class
@isTest
public class EmailWithAttachment_TC {
    public static testMethod void EmailWithAttachment_TCMethod() {
        Lead led = new Lead (
            LastName = 'Test Lead',
            Company = 'Test Company',
            Status = 'Open - Not Contacted'
        );
        insert led;
        Database.LeadConvert lc = new Database.LeadConvert();
        lc.setLeadId(led.Id);
        lc.setDoNotCreateOpportunity(false);
        lc.setConvertedStatus('Converted');
        
        Database.LeadConvertResult lcr = Database.convertLead(lc);
        System.assert(lcr.isSuccess());
        
    }
}
  • March 27, 2020
  • Like
  • 0

Hi All,

I need to have a test class for the below requirement 

.Display list of accounts in a block with checkbox, if the user selects the accounts and click on "show selected Account " button the accounts should display in the pageBlocktable beside the accounts list block
My visaul force page is ready with me ,can anyone help me how to write test class for the above problem ?