• Sandy Shaw
  • NEWBIE
  • 20 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 2
    Replies
I am writing my first trigger. Basically when a new sales opportunity with a company is created, I want the trigger to compare the product2Id of this opportunity with the product2Id from the assets of this company to check if I have saled this product to this company before. If so, I want to set the type of this opportunity to  "Existing_business".
This is my code:
User-added image
I am curious how should I start writing the test for trigger? Thanks in advance!
I am creating a new Apex trigger in one sandbox, and I want to use the Debug Log to debug. I first create a new user trace flag. I put the Traced Entity Type as user and Traced Entity Name as my user name. Then I have the User-added image
this statement in my code. However, after I save the code, the log only shows this User-added image
Could anyone please tell me how to make the Debug Log work? Should I change the Traced Entity Type? Thanks in advance.
Hi,
I am writing a cross object trigger. 
This is my first map: Map<Id,List<Asset>> acc_asset_map = new Map<Id,List<Asset>>();
    for(Id k:account_id){
        List<Asset> asset = new List<Asset>();
        asset = [SELECT Product2Id FROM Asset WHERE AccountId = :k];
        acc_asset_map.put(k,asset);
    }

And this is the second map:      Map<Id,List<OpportunityLineItem>> opp_prod_map = new Map<Id,List<OpportunityLineItem>>();
     for (Id i:opp_id){
         List<OpportunityLineItem> oppLineItem = new List<OpportunityLineItem>();
         oppLineItem = [SELECT Product2Id FROM OpportunityLineItem WHERE OpportunityId = :i];
         opp_prod_map.put(i,oppLineItem);
     }
I want to compare the value of my two maps. So I have a for loop go trough a list of all my AccountId. Then I get all the OpportunityId under each AccountId. With each OpportunityId, I want to check if there is any same Product2Id under my Opportunity and my Asset. Though both of the value I put in my map are 'Product2Id', they are get from different Object types. One is from Asset, and the other is from OpportunityLineItem. 
So am I on the reight direction if I want to check whether the account asset and the opporutnity under that account have the same product?
If so, is there anyway to fix this bug?
Thanks in advance!
I am writing my first trigger. Basically when a new sales opportunity with a company is created, I want the trigger to compare the product2Id of this opportunity with the product2Id from the assets of this company to check if I have saled this product to this company before. If so, I want to set the type of this opportunity to  "Existing_business".
This is my code:
User-added image
I am curious how should I start writing the test for trigger? Thanks in advance!
Hi,
I am writing a cross object trigger. 
This is my first map: Map<Id,List<Asset>> acc_asset_map = new Map<Id,List<Asset>>();
    for(Id k:account_id){
        List<Asset> asset = new List<Asset>();
        asset = [SELECT Product2Id FROM Asset WHERE AccountId = :k];
        acc_asset_map.put(k,asset);
    }

And this is the second map:      Map<Id,List<OpportunityLineItem>> opp_prod_map = new Map<Id,List<OpportunityLineItem>>();
     for (Id i:opp_id){
         List<OpportunityLineItem> oppLineItem = new List<OpportunityLineItem>();
         oppLineItem = [SELECT Product2Id FROM OpportunityLineItem WHERE OpportunityId = :i];
         opp_prod_map.put(i,oppLineItem);
     }
I want to compare the value of my two maps. So I have a for loop go trough a list of all my AccountId. Then I get all the OpportunityId under each AccountId. With each OpportunityId, I want to check if there is any same Product2Id under my Opportunity and my Asset. Though both of the value I put in my map are 'Product2Id', they are get from different Object types. One is from Asset, and the other is from OpportunityLineItem. 
So am I on the reight direction if I want to check whether the account asset and the opporutnity under that account have the same product?
If so, is there anyway to fix this bug?
Thanks in advance!