• tchi1.39595540062922E12
  • NEWBIE
  • 0 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 0
    Replies
Hey all, 

Having some difficulty deploying this trigger. The code coverage is at 100% and it works if I set it as After Update, but i'm getting this error message when i swap the name to After Insert:

Failure Message: "System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, AutoContract: execution of AfterInsert caused by: System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [AccountId]: [Accoun...

Trigger: 

trigger AutoContract on Zuora__SubscriptionProductCharge__c (After Insert) {
List<Contract> listContracts= new List<Contract>();
for(Zuora__SubscriptionProductCharge__c S: Trigger.new){
Contract C= new Contract();
C.Description=S.Zuora__ProductDescription__c;
C.accountid=S.Zuora__Account__r.Id;
C.Type_of_Sale__c=S.Zuora__ProductName__c;
C.Payment_Plan__c=S.Zuora__BillingPeriod__c;
C.Extended_Amount__c=S.Zuora__ExtendedAmount__c;
C.StartDate=S.Zuora__EffectiveStartDate__c;
C.AccountId = S.Zuora__Account__c;
C.RecordTypeId = '01230000000975K';
C.Contract_Total__c=S.Zuora__TotalContractValue__c;
C.Subscription_Charge_Name__c=S.Name;
C.Payment_Terms__c=S.Zuora__BillingPeriod__c;
C.UOM__c=S.Zuora__UOM__c;
C.Monthly_Payment__c=S.Zuora__MonthlyRecurringRevenue__c;
C.SubscriptionName__c=S.Zuora__Subscription__c;
C.Price__c=S.Zuora__Price__c;
C.Quantity__c=S.Zuora__Quantity__c;
C.Period_Start_Date__c=S.Zuora__BillingPeriodStartDay__c;
C.Type__c=S.Zuora__Type__c;
C.Model__c=S.Zuora__Model__c;
C.Rate_Plan_Name__c=S.Zuora__RatePlanName__c;
C.Product_SKU__c=S.Zuora__ProductSKU__c;
C.Rate_Plan_Description__c=S.Zuora__RatePlanDescription__c;
C.Product_Description__c=S.Zuora__ProductDescription__c;
C.Email__c=S.Zuora__Subscription__r.Zuora__CustomerAccount__r.Zuora__BillToWorkEmail__c;
C.Phone_Number__c=S.Zuora__Subscription__r.Zuora__CustomerAccount__r.Zuora__BillToWorkPhone__c;
C.Account_Number__c=S.Account_Number__c;
C.Bill_To_Name__c=S.Bill_To_Name__c;
C.Credit_Card_Expiration__c=S.Credit_Card_Expiration__c;
c.Credit_Card_Number__c=S.Credit_Card_Number__c;
c.Credit_Card_Type__c=S.Credit_Card_Type__c;
C.Email__c=S.Email__c;
C.Phone_Number__c=S.Phone__c;
C.Subscription_Status__c=S.Subscription_Status__c;
C.Subscription_Product_Charge__c=S.Id;
listContracts.add(c);
}

   if(listContracts.isEmpty()== false)
{Database.insert(listContracts);

}


  }

---------------------------


Test Class:

@isTest(SeeAllData=True)

public class AutoContract
{
Static testMethod void insertnewcontract() {

// Switch to the runtime context




List<Contract> ListContract = new List<Contract>();
Contract C = new Contract();
C.Type_of_Sale__c = 'Website';
C.Type__c ='Recurring';
C.StartDate = System.Today();

Account acc = new Account();
acc.Name =  'TestAcc' ;
acc.Customer_Status__c  = 'Active Client';
Insert acc;
Update acc;


Zuora__SubscriptionProductCharge__c spc = new Zuora__SubscriptionProductCharge__c();
spc.Name='Test';
spc.Zuora__ProductName__c = 'Website' ;
spc.Zuora__Type__c = 'Recurring';
spc.Zuora__EffectiveStartDate__c = System.Today();
spc.Zuora__Account__c= acc.Id;
Insert spc;

spc.Name='Test1';
Update spc;

insert ListContract;


}

}

Any tips would be greatly appreciated!