• Sanjay George 1
  • NEWBIE
  • 0 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 3
    Replies
New to this.  Wrote a working apex trigger, but no idea how to write test cases for it?

Here's the trigger code:
trigger CaseResource_CaseTeamMemberCreation on Case_Resource__c (after insert) {
    CaseTeamRole role = [select Name from CaseTeamRole where Name = 'Case Member'];
    List<CaseTeamMember> members = new List<CaseTeamMember>();
  
    for (Case_Resource__c resource: Trigger.new) {
        if (resource.Resource_Name__c != null && resource.Case__c != null) {
            members.add(new CaseTeamMember(
                ParentID = resource.Case__c,
                MemberID = resource.Resource_Name__c,
                TeamRoleID = role.Id

           ));
        }
    }
  
    if (!members.isEmpty()) {
        insert members;
    }
Hi all

I'm executing this query from Java code using REST service:

SELECT Id, Name, StageName, Amount FROM Opportunity WHERE AccountId = 'xyz' AND OwnerId = 'abc'

I have System Administrator role, View All permission, Object level full permission on Opportunity object, all field level permissions on Opportunity fields.

Still i'm getting this error:

sObject type 'Opportunity' is not supported. If you are attempting to use a custom object, be sure to append the '__c' after the entity name. Please reference your WSDL or the describe call for the appropriate names.","errorCode":"INVALID_TYPE"

can you please suggest what i'm missing
Need help with a test class for the following Class. I am new to development and need to get this class above 75%. I didn't write this class so I am kinda stuck. Any help would be great. 

Class
trigger CreateAssetonClosedWon on Opportunity (after insert, after update) {
  Map<String, AssetRollup__c> rollupMap = AssetRollup__c.getAll();
 
     for(Opportunity o: trigger.new){
      if(o.isWon == true && o.HasOpportunityLineItem == true){
         String opptyId = o.Id;
         OpportunityLineItem[] OLI = [Select UnitPrice, Quantity, PricebookEntry.Product2Id,
                                             TotalPrice,
                                             PricebookEntry.Product2.Name, Description, Converted_to_Asset__c,
                                             PricebookEntry.Product2.Create_Asset__c, PricebookEntry.Product2.Sales_Order_Group__c
                                      From OpportunityLineItem
                                      where OpportunityId = :opptyId
                                        and Converted_to_Asset__c = false
                                        and PricebookEntry.Product2.Create_Asset__c = true];
         Asset[] ast = new Asset[]{};
         Asset hotline;
         Asset a = new Asset();
         for(OpportunityLineItem ol: OLI){
            a = new Asset();
          a.AccountId = o.AccountId;
            a.Product2Id = ol.PricebookEntry.Product2Id;
            a.Quantity__c = ol.Quantity;
            a.Price =  ol.TotalPrice;
            a.PurchaseDate = o.CloseDate;
            a.Renewal_Date__c = o.CloseDate.Month() + '/' + o.CloseDate.Day();
            a.Status = 'Purchased';
            a.Description = ol.Description;
            a.Name = ol.PricebookEntry.Product2.Name;
        // TODO:extend this to support matching on sales order group from AssetRollup__c and build a list of rollups         
        if(ol.PricebookEntry.Product2.Sales_Order_Group__c=='International Hotline'){
          if(hotline == null) {
            hotline = a;
            AssetRollup__c rollup = rollupMap.get(ol.PricebookEntry.Product2.Sales_Order_Group__c);
            if (rollup != null){
              hotline.Name = rollup.Asset_Name__c;
              hotline.Product2Id = rollup.ProductId__c;
            }
          }
          else {
            hotline.Quantity__c += a.Quantity__c;
            hotline.Price += ol.TotalPrice;
          }
        }
        else{
              ast.add(a);
        }
           
            ol.Converted_to_Asset__c = true;
       }
       if(hotline != null) {
         ast.add(hotline);
       }
      update OLI;
      
      insert ast;
     }
    }
}

Test Class


@isTest
Public class testReassignCNO {
    
     static testMethod void testPardotScore() {
    
        Account a = new Account();
        a.name = 'TNW (for Competitor Profile)';
        a.OwnerId = '005A0000000gWDt';
        insert a;
       
        Contact q = new Contact();
        q.FirstName = 'Test';
        q.LastName = 'User 1';
        q.pi__score__c = 20;
        q.accountId = a.Id;
        q.OwnerId = '005A0000000gWDt';
        q.No_Longer_Employed__c = true;
        insert q;
       
         Contact c = new Contact();
        c.FirstName = 'Test2';
        c.LastName = 'User 2';
        c.pi__score__c = 20;
        c.accountId = a.Id;
        c.OwnerId = '005F0000003kNza';
        insert c;
        
        a.assign__c = True;
        update a;
       
        
       
    }
}