Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- String [] arrayOfWords = new String[]{'mesa', 'cadeira', 'sofá'};
- System.debug(arrayOfWords[0]);
- //mesa
- Integer [] numeros = new Integer[3];
- numeros[0] = 32;
- numeros[1] = 25;
- numeros[2] = 37;
- System.debug(numeros[2]);
- //37
- Integer [] numeros = new Integer[3];
- numeros[0] = 32;
- numeros[1] = 25;
- numeros[2] = 37;
- System.debug(numeros[2]);
- //**********************************************************************
- Account [] contas = new Account[3];
- contas[0] = new Account(Name='Petrobrás');
- contas[1] = new Account(Name='IBM');
- contas[2] = new Account(Name='IBM');
- System.debug(contas.size());
- System.debug(contas);
- contas.remove(2);
- System.debug(contas.size());
- System.debug(contas);
- //**********************************************************************
- List<String> palavras = new List<String>{'Antônio', 'José'};
- System.debug(palavras.size());//2
- palavras.add('Carlos');
- palavras.add('Kátia');
- System.debug(palavras.size());//4
- System.debug(palavras);//(Antônio, José, Carlos, Kátia)
- //**********************************************************************
- List<String> palavras = new List<String>();
- System.debug(palavras.size());//0
- palavras.add('Carlos');
- palavras.add('Kátia');
- System.debug(palavras.size());//2
- System.debug(palavras);//(Carlos, Kátia)
- //**********************************************************************
- List<SObject> sObjs = new List<sObject>();
- System.debug(sObjs.size());//0
- sObjs.add(new Contact(lastname='Pedro'));
- sObjs.add(new Account(Name='IBM'));
- System.debug(sObjs.size());//2
- System.debug(sObjs);//(contato, conta)
- System.debug(sObjs.get(1));//Conta
- System.debug(sObjs[1]);//Conta
- sObjs.add(new Account(Name='IBM'));
- sObjs.add(new Account(Name='IBM'));
- System.debug(sObjs.size());
- System.debug(sObjs);
- //**********************************************************************
- List<SObject> sObjs = new List<sObject>();
- System.debug(sObjs.size());//0
- Contact cont1 = new Contact(lastname='Pedro');
- sObjs.add(cont1);
- Account acc1 = new Account(Name='IBM');
- sObjs.add(acc1);
- System.debug(sObjs.size());//2
- System.debug(sObjs);//(contato, conta)
- System.debug(sObjs.get(1));//Conta
- System.debug(sObjs[1]);//Conta
- Account acc2 = new Account(Name='IBM');
- sObjs.add(acc2);
- Account acc3 = new Account(Name='IBM');
- sObjs.add(acc3);
- System.debug(sObjs.size());
- System.debug(sObjs);
- //**********************************************************************
- class Cachorro{
- String pelo = 'liso';
- String cor = 'preto';
- public Cachorro(){
- }
- public Cachorro(String pelo, String cor){
- pelo = pelo;
- cor = cor;
- }
- }
- List<Object> objs = new List<Object>();
- objs.add(new Account(Name='IBM'));
- objs.add('Airton');
- objs.add(new Cachorro('liso', 'branco'));
- Cachorro c = new Cachorro('liso', 'preto');
- System.debug(c.cor);
- objs.add(c);
- objs.add(15);
- System.debug(objs.size());
- System.debug(objs);
- System.debug('Objeto no índice 0 da lista: '+objs[0]); //Conta
- System.debug('Objeto no índice 2 da lista: '+objs[2]); //Cachorro
- System.debug('Objeto no índice 4 da lista: '+objs[4]); //Integer
- //Quero pegar a cor do pelo do 2º cachorro
- Cachorro d = new Cachorro();
- d = (Cachorro)objs[3];
- System.debug(d.cor);
- System.debug(((Account)objs[0]).Name);
- System.debug(((SObject)objs[0]).get('Name')); //Aqui o get funciona por se
- //tratar de um sObject
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement