• Ankit Garg 117
  • NEWBIE
  • 40 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 14
    Questions
  • 24
    Replies
Hi,

I have the code which will copy the ''BannerAd'' which is a custom object and shown as a related list on the opportunity, whenever the opportunity is cloned. This is working in the sandbox but I need help with the test class so I can push this to production. Below is the code - 

In order to make it work. I had to define two new Apex classes in the developer console

OppCloneTrigger - a trigger that will file after and Opportunity is saved in the system. Defined like:

trigger OppCloneTrigger on Opportunity (after insert) {
    // Create a variable for adding all the closed opps.
    List<Opportunity>closedOpp = new list<Opportunity>();

    // Run through the list and generated closed opporunities.
    for(Opportunity op : Trigger.new) {
        
        // Only add opportunities that are cloned and either won or closed.

        // (op.StageName != Trigger.oldMap.get(op.Id).StageName) - no need to check for this since it as an insert.
        if(op.isClone()) {
            closedOpp.add(op);
        }
    }

    // Clone the banners
    OppCloneClass.copyBannerAds(closedOpp);
}




and the OppCloneClass - a class that defines a method used to close the banner from original opportunity to the cloned one. Defined:

public class OppCloneClass {
    public static void CopyBannerAds(List<Opportunity> opporunities) {
        // For every opportunity delivered
        for(Opportunity op : opporunities)
        {
            // Only run this for a cloned opportunity.
            if (op.isClone()) {
                // Get the id of the source oppotunity.
                ID sourceId = op.getCloneSourceId();
                
                // Get the banners from the opportunity that the clone originated from. 
                // Need to manually specify the fields retrieved so that clone copy all the fields.
                List<banner__c> banners=[SELECT 
                    Id,
                    IsDeleted,
                    Name,
                    CreatedDate,
                    CreatedById,
                    LastModifiedDate,
                    LastModifiedById,
                    SystemModstamp,
                    LastActivityDate,
                    LastViewedDate,
                    LastReferencedDate,
                    Opportunity__c,
                    Practice_Address__c,
                    Location__c,
                    Inventory_Number__c,
                    Account_or_HCP_Name__c,
                    HS_Contract_GST__c,
                    Competition_Banner__c,
                    Tier__c,
                    Discount__c,
                    Monthly_Banner_Fee__c,
                    Banner_Discount_in__c,
                    Banner_Price_2__c,
                    Group_Purchase_B__c,
                    HS_Total_Price_incl_GST__c,
                    Listing_End_Date__c,
                    HS_Inventory__c,
                    HS_Discount_Price__c,
                    Banner_Region__c,
                    HS_full_Price__c,
                    HS_Specialty__c,
                    HS_Contract_Duration__c,
                 FROM banner__c WHERE Opportunity__c = :sourceId];

                // Create new banner items by cloning all the ones related to the source opportunity. 
                List<banner__c> newBanners = new List<banner__c>();
                for(banner__c banner : banners) {
                    banner__c banclone = banner.clone();
                    banclone.Opportunity__c=op.id;
                    newBanners.add(banclone);
                }
                // Commit new banners into the system.
                insert newBanners;
            }
        }
    }
Hi,

I have the code which will copy the ''BannerAd'' which is a custom object and shown as a related list on the opportunity, whenever the opportunity is cloned. This is working in the sandbox but I need help with the test class so I can push this to production. Below is the code - 

In order to make it work. I had to define two new Apex classes in the developer console

OppCloneTrigger - a trigger that will file after and Opportunity is saved in the system. Defined like:

trigger OppCloneTrigger on Opportunity (after insert) {
    // Create a variable for adding all the closed opps.
    List<Opportunity>closedOpp = new list<Opportunity>();

    // Run through the list and generated closed opporunities.
    for(Opportunity op : Trigger.new) {
        
        // Only add opportunities that are cloned and either won or closed.

        // (op.StageName != Trigger.oldMap.get(op.Id).StageName) - no need to check for this since it as an insert.
        if(op.isClone()) {
            closedOpp.add(op);
        }
    }

    // Clone the banners
    OppCloneClass.copyBannerAds(closedOpp);
}




and the OppCloneClass - a class that defines a method used to close the banner from original opportunity to the cloned one. Defined:

public class OppCloneClass {
    public static void CopyBannerAds(List<Opportunity> opporunities) {
        // For every opportunity delivered
        for(Opportunity op : opporunities)
        {
            // Only run this for a cloned opportunity.
            if (op.isClone()) {
                // Get the id of the source oppotunity.
                ID sourceId = op.getCloneSourceId();
                
                // Get the banners from the opportunity that the clone originated from. 
                // Need to manually specify the fields retrieved so that clone copy all the fields.
                List<banner__c> banners=[SELECT 
                    Id,
                    IsDeleted,
                    Name,
                    CreatedDate,
                    CreatedById,
                    LastModifiedDate,
                    LastModifiedById,
                    SystemModstamp,
                    LastActivityDate,
                    LastViewedDate,
                    LastReferencedDate,
                    Opportunity__c,
                    Practice_Address__c,
                    Location__c,
                    Inventory_Number__c,
                    Account_or_HCP_Name__c,
                    HS_Contract_GST__c,
                    Competition_Banner__c,
                    Tier__c,
                    Discount__c,
                    Monthly_Banner_Fee__c,
                    Banner_Discount_in__c,
                    Banner_Price_2__c,
                    Group_Purchase_B__c,
                    HS_Total_Price_incl_GST__c,
                    Listing_End_Date__c,
                    HS_Inventory__c,
                    HS_Discount_Price__c,
                    Banner_Region__c,
                    HS_full_Price__c,
                    HS_Specialty__c,
                    HS_Contract_Duration__c,
                 FROM banner__c WHERE Opportunity__c = :sourceId];

                // Create new banner items by cloning all the ones related to the source opportunity. 
                List<banner__c> newBanners = new List<banner__c>();
                for(banner__c banner : banners) {
                    banner__c banclone = banner.clone();
                    banclone.Opportunity__c=op.id;
                    newBanners.add(banclone);
                }
                // Commit new banners into the system.
                insert newBanners;
            }
        }
    }
 }
I have a Task Named ''contract follow-up task " What I want is On completion of “contract follow-up task”, AND where opportunity is not Closed Won or Closed Lost, create a “contract follow-up task” assigned to the opportunity owner for 2 days time.
 
Can't do this via PB or WF. 
HI,

We have a custom object called ''Banner''. Whenever a user creates an opportunity, they add a banner to that opportunity. Now, whenever a user closes an opportunity, they clone it and name it ''Renewal (opportunity Name). This way they have created another opportunity for the same business to sell them again in future. 

Now, when they clone the opportunity, the Banner details don't get cloned so they have to add the Banners again. Some opps have 10+ Banners so they have to add them again. Banner is shown as a related list on the opportunity page. How can I get Banners to be cloned with all the information when they clone an opportunity? Can someone please help me with the trigger to achieve this?

Thanks 
Hi, I am very new to the trigger and have very less experience with them.

I want to auto-populate the Comments on Task onto the Chatter. Is this possible via trigger? If yes, can someone please help me with thew trigger. Will be really thankful.

Thanks 
Hi,

I have a custom object called ''Banners'' on Opportuities. When users clone the opportunity, I want this custom object ''Banners'' associated witht he opportunity to be cloned as well. Please advise.

Thanks,
Hi,

I have a custom field (Picklist) called ''BC Onbparding Stage''. I want whenever ''BC Onboarding Stage" is = ''IT Details Received", it Post a message to Slack. 

I have created a Slack Channel called bc-onboarding-alerts and the Bot name is bc_bot

Please help :)
Hi,

I have 2 picklist name Practice Stage and BC Stage. I have created Text Formula Field name ''Funnel Stage''.

Values of "Practice Stage" is  - Cold, Demo Booked, Demo Completed, Interested, Not Interested. 
Values of "BC Stage" is Enabled, Disabled.

What I want is if Practice Stage is NOT equal to Cold, Demo Booked, Demo Completed, Interested, Not Interested ''Funnel Stage'' shows BC Stage value. and IF BC Stage is blank, ''Funnel Stage'' Shows ''Practice Stage'' value. 

Is this possible?
Hey..

I have 4-5 workflows which do the same function on the Account object. They all put a Date Stamp based on different fileds in a picklist. Since we have 5 options in a picklist and we are tracking the date of every option, I have to create 5 different workflows. 

I have little to no experience working with Triggers. Is it possible to achieve this with 1 trigger?


Thanks 
Hey Gurus,

I am newbiew to Triggers. 

Scenerio  - There is a checkbox field on a Account called "Account Visited"? Now if the parent account gets visited, its same as visiting all of its child accounts. 

So I need a trigger if someone checked the box on the Parent account, all of its child accounts gets checked as well and sales rep dont have to go to every child account individually to update.

Cheers
Formula to calculate Products
Okay, so not sure how to frame this but I will try my best.

So we have a custom object called ''Banners''. (Imagine this as an advertising banner on the websites) see image. In the below image, ''Speciality'' is Cardiologist and ''Location'' is Bondi.

Second image will show you how does ''Banner'' object look like as a related list in my Salesforce instance. 

User-added image
User-added image





Now the condition is - Any opportunity can have Maximum of 3 Banners in combination on specilaity and region. For example - we can only allocate/sell Cardiologist in Bondi Juntion only 3 times. Now this can be allocated/sell to any one Opportunity or 3 different opportunities. 

Currently we maintain a spreadsheet to see what regions are empmty for what speciality. Ideally I want to achieve this from SF that if a user is allocating Cardiologist in Bondi junction (where it has already been allocated in this combination 3 times) user will be alerted. SO he/she will not sell any other Banner. 

Reason - the screenshot is from our website and we can only list 3 banners. 

Any help would be greatly appriciated. 

Cheers
Hi Gurus,

So I have a custom object called ''Banner''. Within Banner I have 2 fields called "HS_Speaciality" and "Region (z_Speciality)''

What I am trying to achieve is 1 particular speciality can only be allocated to any particular region maximum of 3 times. Now I wan to check this across all the Banners and not just on 1 Banner. Need a trigger for this. Example- there can only be 3 Physiotherepist in New York, there may be other physioterepistr at other locations though.
Hi Gurus,

I want to convert the Person Accounts to Contcats and then associate those contcats with the Busines Accounts. At the same time I also want to keep all the history of the person accounts on these contacts. 

Please help.
Hi Gurus,

Is it possible to limit a perticular project on all opportunites? For example I have a product called factsheets. I want to limit that to 3. So only 3 times this product can be assigned to a opportunity. 

Note  - I am not talking aboutn limiting the number of products on 1 perticular opp but on al the opps. 

Is this possible via apex or trigger? if yes, can I please have a code. 

Thanks all. 
Hi,

I have the code which will copy the ''BannerAd'' which is a custom object and shown as a related list on the opportunity, whenever the opportunity is cloned. This is working in the sandbox but I need help with the test class so I can push this to production. Below is the code - 

In order to make it work. I had to define two new Apex classes in the developer console

OppCloneTrigger - a trigger that will file after and Opportunity is saved in the system. Defined like:

trigger OppCloneTrigger on Opportunity (after insert) {
    // Create a variable for adding all the closed opps.
    List<Opportunity>closedOpp = new list<Opportunity>();

    // Run through the list and generated closed opporunities.
    for(Opportunity op : Trigger.new) {
        
        // Only add opportunities that are cloned and either won or closed.

        // (op.StageName != Trigger.oldMap.get(op.Id).StageName) - no need to check for this since it as an insert.
        if(op.isClone()) {
            closedOpp.add(op);
        }
    }

    // Clone the banners
    OppCloneClass.copyBannerAds(closedOpp);
}




and the OppCloneClass - a class that defines a method used to close the banner from original opportunity to the cloned one. Defined:

public class OppCloneClass {
    public static void CopyBannerAds(List<Opportunity> opporunities) {
        // For every opportunity delivered
        for(Opportunity op : opporunities)
        {
            // Only run this for a cloned opportunity.
            if (op.isClone()) {
                // Get the id of the source oppotunity.
                ID sourceId = op.getCloneSourceId();
                
                // Get the banners from the opportunity that the clone originated from. 
                // Need to manually specify the fields retrieved so that clone copy all the fields.
                List<banner__c> banners=[SELECT 
                    Id,
                    IsDeleted,
                    Name,
                    CreatedDate,
                    CreatedById,
                    LastModifiedDate,
                    LastModifiedById,
                    SystemModstamp,
                    LastActivityDate,
                    LastViewedDate,
                    LastReferencedDate,
                    Opportunity__c,
                    Practice_Address__c,
                    Location__c,
                    Inventory_Number__c,
                    Account_or_HCP_Name__c,
                    HS_Contract_GST__c,
                    Competition_Banner__c,
                    Tier__c,
                    Discount__c,
                    Monthly_Banner_Fee__c,
                    Banner_Discount_in__c,
                    Banner_Price_2__c,
                    Group_Purchase_B__c,
                    HS_Total_Price_incl_GST__c,
                    Listing_End_Date__c,
                    HS_Inventory__c,
                    HS_Discount_Price__c,
                    Banner_Region__c,
                    HS_full_Price__c,
                    HS_Specialty__c,
                    HS_Contract_Duration__c,
                 FROM banner__c WHERE Opportunity__c = :sourceId];

                // Create new banner items by cloning all the ones related to the source opportunity. 
                List<banner__c> newBanners = new List<banner__c>();
                for(banner__c banner : banners) {
                    banner__c banclone = banner.clone();
                    banclone.Opportunity__c=op.id;
                    newBanners.add(banclone);
                }
                // Commit new banners into the system.
                insert newBanners;
            }
        }
    }
Hi,

I have the code which will copy the ''BannerAd'' which is a custom object and shown as a related list on the opportunity, whenever the opportunity is cloned. This is working in the sandbox but I need help with the test class so I can push this to production. Below is the code - 

In order to make it work. I had to define two new Apex classes in the developer console

OppCloneTrigger - a trigger that will file after and Opportunity is saved in the system. Defined like:

trigger OppCloneTrigger on Opportunity (after insert) {
    // Create a variable for adding all the closed opps.
    List<Opportunity>closedOpp = new list<Opportunity>();

    // Run through the list and generated closed opporunities.
    for(Opportunity op : Trigger.new) {
        
        // Only add opportunities that are cloned and either won or closed.

        // (op.StageName != Trigger.oldMap.get(op.Id).StageName) - no need to check for this since it as an insert.
        if(op.isClone()) {
            closedOpp.add(op);
        }
    }

    // Clone the banners
    OppCloneClass.copyBannerAds(closedOpp);
}




and the OppCloneClass - a class that defines a method used to close the banner from original opportunity to the cloned one. Defined:

public class OppCloneClass {
    public static void CopyBannerAds(List<Opportunity> opporunities) {
        // For every opportunity delivered
        for(Opportunity op : opporunities)
        {
            // Only run this for a cloned opportunity.
            if (op.isClone()) {
                // Get the id of the source oppotunity.
                ID sourceId = op.getCloneSourceId();
                
                // Get the banners from the opportunity that the clone originated from. 
                // Need to manually specify the fields retrieved so that clone copy all the fields.
                List<banner__c> banners=[SELECT 
                    Id,
                    IsDeleted,
                    Name,
                    CreatedDate,
                    CreatedById,
                    LastModifiedDate,
                    LastModifiedById,
                    SystemModstamp,
                    LastActivityDate,
                    LastViewedDate,
                    LastReferencedDate,
                    Opportunity__c,
                    Practice_Address__c,
                    Location__c,
                    Inventory_Number__c,
                    Account_or_HCP_Name__c,
                    HS_Contract_GST__c,
                    Competition_Banner__c,
                    Tier__c,
                    Discount__c,
                    Monthly_Banner_Fee__c,
                    Banner_Discount_in__c,
                    Banner_Price_2__c,
                    Group_Purchase_B__c,
                    HS_Total_Price_incl_GST__c,
                    Listing_End_Date__c,
                    HS_Inventory__c,
                    HS_Discount_Price__c,
                    Banner_Region__c,
                    HS_full_Price__c,
                    HS_Specialty__c,
                    HS_Contract_Duration__c,
                 FROM banner__c WHERE Opportunity__c = :sourceId];

                // Create new banner items by cloning all the ones related to the source opportunity. 
                List<banner__c> newBanners = new List<banner__c>();
                for(banner__c banner : banners) {
                    banner__c banclone = banner.clone();
                    banclone.Opportunity__c=op.id;
                    newBanners.add(banclone);
                }
                // Commit new banners into the system.
                insert newBanners;
            }
        }
    }
 }
HI,

We have a custom object called ''Banner''. Whenever a user creates an opportunity, they add a banner to that opportunity. Now, whenever a user closes an opportunity, they clone it and name it ''Renewal (opportunity Name). This way they have created another opportunity for the same business to sell them again in future. 

Now, when they clone the opportunity, the Banner details don't get cloned so they have to add the Banners again. Some opps have 10+ Banners so they have to add them again. Banner is shown as a related list on the opportunity page. How can I get Banners to be cloned with all the information when they clone an opportunity? Can someone please help me with the trigger to achieve this?

Thanks 
Hi, I am very new to the trigger and have very less experience with them.

I want to auto-populate the Comments on Task onto the Chatter. Is this possible via trigger? If yes, can someone please help me with thew trigger. Will be really thankful.

Thanks 
Hi,

I have a custom object called ''Banners'' on Opportuities. When users clone the opportunity, I want this custom object ''Banners'' associated witht he opportunity to be cloned as well. Please advise.

Thanks,
Hi,

I have 2 picklist name Practice Stage and BC Stage. I have created Text Formula Field name ''Funnel Stage''.

Values of "Practice Stage" is  - Cold, Demo Booked, Demo Completed, Interested, Not Interested. 
Values of "BC Stage" is Enabled, Disabled.

What I want is if Practice Stage is NOT equal to Cold, Demo Booked, Demo Completed, Interested, Not Interested ''Funnel Stage'' shows BC Stage value. and IF BC Stage is blank, ''Funnel Stage'' Shows ''Practice Stage'' value. 

Is this possible?
Hey..

I have 4-5 workflows which do the same function on the Account object. They all put a Date Stamp based on different fileds in a picklist. Since we have 5 options in a picklist and we are tracking the date of every option, I have to create 5 different workflows. 

I have little to no experience working with Triggers. Is it possible to achieve this with 1 trigger?


Thanks