Skip to main content
Serghei Sleptov 님이 #Apex에 질문했습니다

Hi Everyone,

I've created a simpletrigger that creates a new record of custom object: Hosted_PBX_Deployment__c when a new Opportunity is created.

Now I need to set a value to a fiield: Rack_4_19_two_post_Qty__c in custom object that depends on a value of an Account field: All_Network_Devices_Qty__c

so if Account.All_Network_Devices_Qty__c <=11 then Rack_4_19_two_post_Qty__c =1 

what is the best way to reffer to an Account field from Hosted_PBX_Deployment__c trigger?

this is my trigger:

trigger AutoCreateHPBXdeployment on Opportunity (after insert) {

List<Hosted_PBX_Deployment__c> newHPBX = new List<Hosted_PBX_Deployment__c>();

  for (Opportunity opp : Trigger.new) {

      if(opp.Hosted_PBX__c=='Yes'){

    Hosted_PBX_Deployment__c hpbx = new Hosted_PBX_Deployment__c();

    hpbx.Opportunity__c  = opp.Id;

    hpbx.Opportunity_Account__c = opp.AccountId;

   

 

    newHPBX.add(hpbx);

      }

  }

  insert newHPBX;

}

Thank you!
답변 4개
  1. 2018년 2월 15일 오후 3:51
    @Serghei Sleptov - Yes..using set will be better approach.

    @Krishnakumari - Thanks for bringing up process builder, Certainly that would be easy and OOB. But the original Question was asked for trigger...

    --

    Thanks,

    Prashant
0/9000