• Cubs 42
  • NEWBIE
  • 15 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 2
    Replies
hi,

I am having a lot of trouble phasing this Json get the customer and subscriptions out of the data. wondering if someone could help.
 
{
  "id": "evt_1E3WsQLoXENPhT9XccQX3cWm",
  "object": "event",
  "api_version": "2018-09-24",
  "created": 1550099449,
  "data": {
    "object": {
      "id": "cus_EWa2QH7ZQLe6QD",
      "object": "customer",
      "account_balance": 0,
      "created": 1550099447,
      "currency": "aud",
      "default_source": null,
      "delinquent": false,
      "description": null,
      "discount": null,
      "email": null,
      "invoice_prefix": "B7409C7",
      "invoice_settings": {
        "custom_fields": null,
        "footer": null
      },
      "livemode": false,
      "metadata": {
        "supplierId": "40763"
      },
      "shipping": null,
      "sources": {
        "object": "list",
        "data": [

        ],
        "has_more": false,
        "total_count": 0,
        "url": "/v1/customers/cus_EWa2QH7ZQLe6QD/sources"
      },
      "subscriptions": {
        "object": "list",
        "data": [
          {
            "id": "sub_EWa2VTwVYCLme1",
            "object": "subscription",
            "application_fee_percent": null,
            "billing": "charge_automatically",
            "billing_cycle_anchor": 1550099449,
            "billing_thresholds": null,
            "cancel_at": null,
            "cancel_at_period_end": false,
            "canceled_at": null,
            "created": 1550099449,
            "current_period_end": 1552518649,
            "current_period_start": 1550099449,
            "customer": "cus_EWa2QH7ZQLe6QD",
            "days_until_due": null,
            "default_source": null,
            "discount": null,
            "ended_at": null,
            "items": {
              "object": "list",
              "data": [
                {
                  "id": "si_EWa29P6l36rROx",
                  "object": "subscription_item",
                  "billing_thresholds": null,
                  "created": 1550099449,
                  "metadata": {
                  },
                  "plan": {
                    "id": "plan_ELouSNjcX75qtE",
                    "object": "plan",
                    "active": true,
                    "aggregate_usage": "sum",
                    "amount": null,
                    "billing_scheme": "tiered",
                    "created": 1547617720,
                    "currency": "aud",
                    "interval": "month",
                    "interval_count": 1,
                    "livemode": false,
                    "metadata": {
                      "plan_code": "supplier"
                    },
                    "nickname": "Supplier Connections",
                    "product": "prod_DxNq5IpOJWmkEk",
                    "tiers": [
                      {
                        "flat_amount": 0,
                        "unit_amount": null,
                        "up_to": 5
                      },
                      {
                        "flat_amount": null,
                        "unit_amount": 400,
                        "up_to": 100
                      },
                      {
                        "flat_amount": null,
                        "unit_amount": 380,
                        "up_to": 200
                      },
                      {
                        "flat_amount": null,
                        "unit_amount": 360,
                        "up_to": 400
                      },
                      {
                        "flat_amount": null,
                        "unit_amount": 340,
                        "up_to": 500
                      },
                      {
                        "flat_amount": null,
                        "unit_amount": 320,
                        "up_to": 600
                      },
                      {
                        "flat_amount": null,
                        "unit_amount": 300,
                        "up_to": 700
                      },
                      {
                        "flat_amount": null,
                        "unit_amount": 280,
                        "up_to": 800
                      },
                      {
                        "flat_amount": null,
                        "unit_amount": 260,
                        "up_to": 900
                      },
                      {
                        "flat_amount": null,
                        "unit_amount": 240,
                        "up_to": 1000
                      },
                      {
                        "flat_amount": null,
                        "unit_amount": 240,
                        "up_to": 1200
                      },
                      {
                        "flat_amount": null,
                        "unit_amount": 220,
                        "up_to": 1300
                      },
                      {
                        "flat_amount": null,
                        "unit_amount": 180,
                        "up_to": 1500
                      },
                      {
                        "flat_amount": null,
                        "unit_amount": 160,
                        "up_to": null
                      }
                    ],
                    "tiers_mode": "graduated",
                    "transform_usage": null,
                    "trial_period_days": null,
                    "usage_type": "metered"
                  },
                  "subscription": "sub_EWa2VTwVYCLme1"
                }
              ],
              "has_more": false,
              "total_count": 1,
              "url": "/v1/subscription_items?subscription=sub_EWa2VTwVYCLme1"
            },
            "livemode": false,
            "metadata": {
            },
            "plan": {
              "id": "plan_ELouSNjcX75qtE",
              "object": "plan",
              "active": true,
              "aggregate_usage": "sum",
              "amount": null,
              "billing_scheme": "tiered",
              "created": 1547617720,
              "currency": "aud",
              "interval": "month",
              "interval_count": 1,
              "livemode": false,
              "metadata": {
                "plan_code": "supplier"
              },
              "nickname": "Supplier Connections",
              "product": "prod_DxNq5IpOJWmkEk",
              "tiers": [
                {
                  "flat_amount": 0,
                  "unit_amount": null,
                  "up_to": 5
                },
                {
                  "flat_amount": null,
                  "unit_amount": 400,
                  "up_to": 100
                },
                {
                  "flat_amount": null,
                  "unit_amount": 380,
                  "up_to": 200
                },
                {
                  "flat_amount": null,
                  "unit_amount": 360,
                  "up_to": 400
                },
                {
                  "flat_amount": null,
                  "unit_amount": 340,
                  "up_to": 500
                },
                {
                  "flat_amount": null,
                  "unit_amount": 320,
                  "up_to": 600
                },
                {
                  "flat_amount": null,
                  "unit_amount": 300,
                  "up_to": 700
                },
                {
                  "flat_amount": null,
                  "unit_amount": 280,
                  "up_to": 800
                },
                {
                  "flat_amount": null,
                  "unit_amount": 260,
                  "up_to": 900
                },
                {
                  "flat_amount": null,
                  "unit_amount": 240,
                  "up_to": 1000
                },
                {
                  "flat_amount": null,
                  "unit_amount": 240,
                  "up_to": 1200
                },
                {
                  "flat_amount": null,
                  "unit_amount": 220,
                  "up_to": 1300
                },
                {
                  "flat_amount": null,
                  "unit_amount": 180,
                  "up_to": 1500
                },
                {
                  "flat_amount": null,
                  "unit_amount": 160,
                  "up_to": null
                }
              ],
              "tiers_mode": "graduated",
              "transform_usage": null,
              "trial_period_days": null,
              "usage_type": "metered"
            },
            "quantity": 1,
            "schedule": null,
            "start": 1550099449,
            "status": "active",
            "tax_percent": 10.0,
            "trial_end": null,
            "trial_start": null
          }
        ],
        "has_more": false,
        "total_count": 1,
        "url": "/v1/customers/cus_EWa2QH7ZQLe6QD/subscriptions"
      },
      "tax_info": null,
      "tax_info_verification": null
    },
    "previous_attributes": {
      "currency": null
    }
  },
  "livemode": false,
  "pending_webhooks": 3,
  "request": {
    "id": "req_Is4MSbnoDdu4pi",
    "idempotency_key": null
  },
  "type": "customer.updated"
}

 
i broke my salesforce. need 1% code coverage on this trigger quickly and i dont know where to start

my trigger
 
/*
 * @description Trigger for OpportunityLineItem - this trigger has no test class 
 * @author Tristan Harley 
 * @date 9.MAR.2017
 */

trigger OpportunityLineItemsTrigger on OpportunityLineItem (before insert, before update)

{
    //create list of related object ids 
    Set<string> setOppId = new Set<String>();
    Set<string> setProdId = new Set<String>();
    
    //Populate the lists related object ids to the OpportunityLineItem 
    for( OpportunityLineItem opli : trigger.New )
    {
        setOppId.add(opli.opportunityid);
        setProdId.add(opli.product2id);
    }
    
    //Check if related object ids are populated
    if( setOppId.size() > 0 && setProdId.size() > 0)
    {
        //Map the related object from the lists 
        Map<Id,Opportunity> mapOpp = new  Map<Id,Opportunity> ([select id ,Licensed_Months__c from Opportunity where id in :setOppId ] );
        Map<Id,Product2> mapProd = new  Map<Id,Product2> ([select id ,e3_Product_License__c ,Partners_Share__c from Product2 where id in :setProdId] );
        
        //loop through the OpportunityLineItem that where trigged
        for( OpportunityLineItem opli : trigger.New )
        {
            //Set Defalts on the OpportunityLineItem that where trigged
            if(Trigger.isInsert)
            { 
                opli.Discount = 0;
            }
            
            //check if there is a opportunity related to the OpportunityLineItem
            if(Trigger.isInsert)
            {  
                if(mapOpp.containsKey(opli.opportunityid) )
                {
                    //Match the related record
                    Opportunity opp = mapOpp.get(opli.opportunityid);
                    
                    //Set fields on the OpportunityLineItem that where trigged 
                    System.debug('----------->'+opp.Licensed_Months__c); 
                    opli.Licensed_Months__c = opp.Licensed_Months__c;
                              
                }
            }
            
             //check if there is a product related to the OpportunityLineItem
            if(Trigger.isInsert)
            {
                if(mapProd.containsKey(opli.product2id) )
                {
                    //Match the related record
                    Product2 prod = mapProd.get(opli.product2id);
                    
                    //Set fields on the OpportunityLineItem that where trigged
                    System.debug('----------->'+prod.e3_Product_License__c);
                    opli.e3_Product_Licensing__c = prod.e3_Product_License__c;
                    
                    System.debug('----------->'+prod.Partners_Share__c );
                    opli.Partners_Share__c = prod.Partners_Share__c ;
                              
                }
            }
        } 
    }
 
}

 
hi,

I am having a lot of trouble phasing this Json get the customer and subscriptions out of the data. wondering if someone could help.
 
{
  "id": "evt_1E3WsQLoXENPhT9XccQX3cWm",
  "object": "event",
  "api_version": "2018-09-24",
  "created": 1550099449,
  "data": {
    "object": {
      "id": "cus_EWa2QH7ZQLe6QD",
      "object": "customer",
      "account_balance": 0,
      "created": 1550099447,
      "currency": "aud",
      "default_source": null,
      "delinquent": false,
      "description": null,
      "discount": null,
      "email": null,
      "invoice_prefix": "B7409C7",
      "invoice_settings": {
        "custom_fields": null,
        "footer": null
      },
      "livemode": false,
      "metadata": {
        "supplierId": "40763"
      },
      "shipping": null,
      "sources": {
        "object": "list",
        "data": [

        ],
        "has_more": false,
        "total_count": 0,
        "url": "/v1/customers/cus_EWa2QH7ZQLe6QD/sources"
      },
      "subscriptions": {
        "object": "list",
        "data": [
          {
            "id": "sub_EWa2VTwVYCLme1",
            "object": "subscription",
            "application_fee_percent": null,
            "billing": "charge_automatically",
            "billing_cycle_anchor": 1550099449,
            "billing_thresholds": null,
            "cancel_at": null,
            "cancel_at_period_end": false,
            "canceled_at": null,
            "created": 1550099449,
            "current_period_end": 1552518649,
            "current_period_start": 1550099449,
            "customer": "cus_EWa2QH7ZQLe6QD",
            "days_until_due": null,
            "default_source": null,
            "discount": null,
            "ended_at": null,
            "items": {
              "object": "list",
              "data": [
                {
                  "id": "si_EWa29P6l36rROx",
                  "object": "subscription_item",
                  "billing_thresholds": null,
                  "created": 1550099449,
                  "metadata": {
                  },
                  "plan": {
                    "id": "plan_ELouSNjcX75qtE",
                    "object": "plan",
                    "active": true,
                    "aggregate_usage": "sum",
                    "amount": null,
                    "billing_scheme": "tiered",
                    "created": 1547617720,
                    "currency": "aud",
                    "interval": "month",
                    "interval_count": 1,
                    "livemode": false,
                    "metadata": {
                      "plan_code": "supplier"
                    },
                    "nickname": "Supplier Connections",
                    "product": "prod_DxNq5IpOJWmkEk",
                    "tiers": [
                      {
                        "flat_amount": 0,
                        "unit_amount": null,
                        "up_to": 5
                      },
                      {
                        "flat_amount": null,
                        "unit_amount": 400,
                        "up_to": 100
                      },
                      {
                        "flat_amount": null,
                        "unit_amount": 380,
                        "up_to": 200
                      },
                      {
                        "flat_amount": null,
                        "unit_amount": 360,
                        "up_to": 400
                      },
                      {
                        "flat_amount": null,
                        "unit_amount": 340,
                        "up_to": 500
                      },
                      {
                        "flat_amount": null,
                        "unit_amount": 320,
                        "up_to": 600
                      },
                      {
                        "flat_amount": null,
                        "unit_amount": 300,
                        "up_to": 700
                      },
                      {
                        "flat_amount": null,
                        "unit_amount": 280,
                        "up_to": 800
                      },
                      {
                        "flat_amount": null,
                        "unit_amount": 260,
                        "up_to": 900
                      },
                      {
                        "flat_amount": null,
                        "unit_amount": 240,
                        "up_to": 1000
                      },
                      {
                        "flat_amount": null,
                        "unit_amount": 240,
                        "up_to": 1200
                      },
                      {
                        "flat_amount": null,
                        "unit_amount": 220,
                        "up_to": 1300
                      },
                      {
                        "flat_amount": null,
                        "unit_amount": 180,
                        "up_to": 1500
                      },
                      {
                        "flat_amount": null,
                        "unit_amount": 160,
                        "up_to": null
                      }
                    ],
                    "tiers_mode": "graduated",
                    "transform_usage": null,
                    "trial_period_days": null,
                    "usage_type": "metered"
                  },
                  "subscription": "sub_EWa2VTwVYCLme1"
                }
              ],
              "has_more": false,
              "total_count": 1,
              "url": "/v1/subscription_items?subscription=sub_EWa2VTwVYCLme1"
            },
            "livemode": false,
            "metadata": {
            },
            "plan": {
              "id": "plan_ELouSNjcX75qtE",
              "object": "plan",
              "active": true,
              "aggregate_usage": "sum",
              "amount": null,
              "billing_scheme": "tiered",
              "created": 1547617720,
              "currency": "aud",
              "interval": "month",
              "interval_count": 1,
              "livemode": false,
              "metadata": {
                "plan_code": "supplier"
              },
              "nickname": "Supplier Connections",
              "product": "prod_DxNq5IpOJWmkEk",
              "tiers": [
                {
                  "flat_amount": 0,
                  "unit_amount": null,
                  "up_to": 5
                },
                {
                  "flat_amount": null,
                  "unit_amount": 400,
                  "up_to": 100
                },
                {
                  "flat_amount": null,
                  "unit_amount": 380,
                  "up_to": 200
                },
                {
                  "flat_amount": null,
                  "unit_amount": 360,
                  "up_to": 400
                },
                {
                  "flat_amount": null,
                  "unit_amount": 340,
                  "up_to": 500
                },
                {
                  "flat_amount": null,
                  "unit_amount": 320,
                  "up_to": 600
                },
                {
                  "flat_amount": null,
                  "unit_amount": 300,
                  "up_to": 700
                },
                {
                  "flat_amount": null,
                  "unit_amount": 280,
                  "up_to": 800
                },
                {
                  "flat_amount": null,
                  "unit_amount": 260,
                  "up_to": 900
                },
                {
                  "flat_amount": null,
                  "unit_amount": 240,
                  "up_to": 1000
                },
                {
                  "flat_amount": null,
                  "unit_amount": 240,
                  "up_to": 1200
                },
                {
                  "flat_amount": null,
                  "unit_amount": 220,
                  "up_to": 1300
                },
                {
                  "flat_amount": null,
                  "unit_amount": 180,
                  "up_to": 1500
                },
                {
                  "flat_amount": null,
                  "unit_amount": 160,
                  "up_to": null
                }
              ],
              "tiers_mode": "graduated",
              "transform_usage": null,
              "trial_period_days": null,
              "usage_type": "metered"
            },
            "quantity": 1,
            "schedule": null,
            "start": 1550099449,
            "status": "active",
            "tax_percent": 10.0,
            "trial_end": null,
            "trial_start": null
          }
        ],
        "has_more": false,
        "total_count": 1,
        "url": "/v1/customers/cus_EWa2QH7ZQLe6QD/subscriptions"
      },
      "tax_info": null,
      "tax_info_verification": null
    },
    "previous_attributes": {
      "currency": null
    }
  },
  "livemode": false,
  "pending_webhooks": 3,
  "request": {
    "id": "req_Is4MSbnoDdu4pi",
    "idempotency_key": null
  },
  "type": "customer.updated"
}

 
i broke my salesforce. need 1% code coverage on this trigger quickly and i dont know where to start

my trigger
 
/*
 * @description Trigger for OpportunityLineItem - this trigger has no test class 
 * @author Tristan Harley 
 * @date 9.MAR.2017
 */

trigger OpportunityLineItemsTrigger on OpportunityLineItem (before insert, before update)

{
    //create list of related object ids 
    Set<string> setOppId = new Set<String>();
    Set<string> setProdId = new Set<String>();
    
    //Populate the lists related object ids to the OpportunityLineItem 
    for( OpportunityLineItem opli : trigger.New )
    {
        setOppId.add(opli.opportunityid);
        setProdId.add(opli.product2id);
    }
    
    //Check if related object ids are populated
    if( setOppId.size() > 0 && setProdId.size() > 0)
    {
        //Map the related object from the lists 
        Map<Id,Opportunity> mapOpp = new  Map<Id,Opportunity> ([select id ,Licensed_Months__c from Opportunity where id in :setOppId ] );
        Map<Id,Product2> mapProd = new  Map<Id,Product2> ([select id ,e3_Product_License__c ,Partners_Share__c from Product2 where id in :setProdId] );
        
        //loop through the OpportunityLineItem that where trigged
        for( OpportunityLineItem opli : trigger.New )
        {
            //Set Defalts on the OpportunityLineItem that where trigged
            if(Trigger.isInsert)
            { 
                opli.Discount = 0;
            }
            
            //check if there is a opportunity related to the OpportunityLineItem
            if(Trigger.isInsert)
            {  
                if(mapOpp.containsKey(opli.opportunityid) )
                {
                    //Match the related record
                    Opportunity opp = mapOpp.get(opli.opportunityid);
                    
                    //Set fields on the OpportunityLineItem that where trigged 
                    System.debug('----------->'+opp.Licensed_Months__c); 
                    opli.Licensed_Months__c = opp.Licensed_Months__c;
                              
                }
            }
            
             //check if there is a product related to the OpportunityLineItem
            if(Trigger.isInsert)
            {
                if(mapProd.containsKey(opli.product2id) )
                {
                    //Match the related record
                    Product2 prod = mapProd.get(opli.product2id);
                    
                    //Set fields on the OpportunityLineItem that where trigged
                    System.debug('----------->'+prod.e3_Product_License__c);
                    opli.e3_Product_Licensing__c = prod.e3_Product_License__c;
                    
                    System.debug('----------->'+prod.Partners_Share__c );
                    opli.Partners_Share__c = prod.Partners_Share__c ;
                              
                }
            }
        } 
    }
 
}