当前位置:K88软件开发文章中心编程语言非主流编程语言Apex → 文章内容

Apex - 对象

减小字体 增大字体 作者:佚名  来源:网上搜集  发布时间:2019-1-15 16:30:49

由 kaikai0220 创建,youj 最后一次修改 2016-12-12 类的实例称为对象。 就Salesforce而言,对象可以是类,也可以创建sObject的对象。 从类创建对象你可以在Java或其他面向对象的编程语言创建一个类的对象下面是一个名为MyClass的类的示例: //Sample Class Examplepublic class MyClass {    Integer myInteger = 10;    public void myMethod (Integer multiplier) {        Integer multiplicationResult;        multiplicationResult=multiplier*myInteger;        System.debug('Multiplication is '+multiplicationResult);    }}这是一个实例类,即调用或访问此类的变量或方法,必须创建此类的实例,然后可以执行所有操作。 //Object Creation//Creating an object of classMyClass objClass = new MyClass();//Calling Class method using Class instanceobjClass.myMethod(100);sObject创建 如您所知,sObjects是Salesforce中用于存储数据的对象。 例如,帐户,联系人等是自定义对象。 您可以创建这些sObject的对象实例。 下面是sObject初始化的示例,以及如何使用点表示法访问特定对象的字段,并将值分配给字段。 //Execute the below code in Developer console by simply pasting it//Standard Object Initialization for Account sObjectAccount objAccount = new Account(); //Object initializationobjAccount.Name = 'Testr Account';  //Assigning the value to field Name of AccountobjAccount.Description = 'Test Account';insert objAccount;//Creating record using DMLSystem.debug('Records Has been created '+objAccount);//Custom sObject initialization and assignment of values to fieldAPEX_Customer_c objCustomer = new APEX_Customer_c ();objCustomer.Name = 'ABC Customer';objCustomer.APEX_Customer_Decscription_c = 'Test Description';insert objCustomer;System.debug('Records Has been created '+objCustomer);静态初始化当加载类时,静态方法和变量只初始化一次。 静态变量不会作为Visualforce页面的视图状态的一部分传输。 下面是静态方法以及静态变量的示例。 //Sample Class Example with Static Methodpublic class MyStaticClass {    Static Integer myInteger = 10;    public static void myMethod (Integer multiplier) {        Integer multiplicationResult;        multiplicationResult=multiplier*myInteger;        System.debug('Multiplication is '+multiplicationResult);    }}//Calling the Class Method using Class Name and not using the instance objectMyStaticClass.myMethod(100);静态变量使用当类加载时静态变量只会被实例化一次,这种现象可以用来避免触发递归。 静态变量值将在相同的执行上下文中相同,并且正在执行的任何类,触发器或代码可以引用它并防止递归。

Apex - 对象