New 2
New 2
}
}
}
public static void defaultstatus(list<account> acc){
for(account acc1 : acc){
if(acc1.status__c ==null){
acc1.status__c ='created';
}
}
}
public static void changedescrption(list<account> acc1){
for (account acc2 : acc1){
if (acc2.status__c != null && acc2.status__c =='created'){
acc2.Description='the account is created';
}
}
@isTest
public class test22 {
@testSetUp
public static void method1(){
list <Account> accc = new list <Account>();
Account acc=new Account();
acc.name= 'chinnareddy';
acc.status__c = null;
//acc.adderror('please select any value');
accc.add(acc) ;
Account acc1 =new Account();
acc1.name= 'chinna1';
acc1.status__c ='created' ;
accc.add(acc1) ;
Account acc2 =new Account();
acc2.name= 'chinna2';
acc2.status__c ='Closed' ;
accc.add(acc2) ;
Account acc4 =new Account();
acc4.name= 'chinna3';
acc4.Description=null;
acc4.Description='please enter any description';
accc.add(acc4) ;
Account acc5 =new Account();
acc5.name= 'chinna5';
acc5.city__c='Anantapur';
accc.add(acc5) ;
Account acc6 =new Account();
acc6.name= 'chinna5';
acc6.AnnualRevenue=1;
accc.add(acc6) ;
insert accc;
}
@isTest
public static void method2(){
List<Account> accList=[select Id,Name,status__c, Description,phone from
Account];
list<contact> conlist=[select AccountId from contact ];
//accountexample1.accounttocontact(accList);
//accountexample1.accounttocontactupdated(accList);
//accountexample1.througherrorinaccount(accList);
accountexample1.makemandataryfieldstatus(accList);
accountexample1.defaultdescription(accList);
accountexample1.defaultstatus(accList);
accountexample1.changedescrption(accList);
}
}
}
if( !conlist.isempty()){
insert conlist;
}
}
public static void accounttocontactupdated(list<account> acc1){
list <contact> conlist = new list <contact> ();
list <id> idlist = new list <id> ();
for (account acc2 : acc1){
if(acc2.status__c=='Created'){
contact con = new contact();
con.AccountId=acc2.Id;
con.LastName=acc2.Name;
conlist.add(con);
}else if(acc2.status__c=='Closed'){
contact con = new contact();
con.AccountId=acc2.Id;
con.LastName=acc2.Name;
conlist.add(con);
}
if( !conlis
}t.isempty()){
insert conlist;
}
}
public static void restrictchildrecord(list <account> acc1){
integer noofrecords =0;
list<contact> conlist = new list<contact> ();
for (account acc2:acc1){
if (acc2.city__c =='Anantapur'){
noofrecords =(integer)acc2.no_of_records__c;
for(integer i=1; i<= noofrecords; i++){
contact con = new contact();
con.Lastname = acc2.Name;
con.MobilePhone = acc2.Phone;
con.AccountId = acc2.Id;
conList.add(con);
}
}
if(!conlist.isempty()){
insert conlist;
}
}
@testSetUp
public static void method1(){
list <Account> accc = new list <Account>();
Account acc=new Account();
acc.name= 'chinnareddy';
acc.status__c = null;
//acc.adderror('please select any value');
accc.add(acc) ;
Account acc1 =new Account();
acc1.name= 'chinna1';
acc1.status__c ='created' ;
accc.add(acc1) ;
Account acc2 =new Account();
acc2.name= 'chinna2';
acc2.status__c ='Closed' ;
accc.add(acc2) ;
Account acc4 =new Account();
acc4.name= 'chinna3';
acc4.Description=null;
acc4.Description='please enter any description';
accc.add(acc4) ;
Account acc5 =new Account();
acc5.name= 'chinna5';
acc5.city__c='Anantapur';
accc.add(acc5) ;
Account acc6 =new Account();
acc6.name= 'chinna5';
acc6.AnnualRevenue=1;
accc.add(acc6) ;
insert accc;
}
@isTest
public static void method2(){
List<Account> accList=[select Id,Name,status__c, Description,phone from
Account];
list<contact> conlist=[select AccountId from contact ];
accountexample1.accounttocontact(accList);
accountexample1.accounttocontactupdated(accList);
// accountexample1.makemandataryfieldstatus(accList);
//accountexample1.defaultdescription(accList);
//accountexample1.defaultstatus(accList);
//accountexample1.changedescrption(accList);
example 7
public class example3 {
public static void througherrorinaccount(list <account> acc1){
list<contact> conlist = new list<contact> ();
for (account acc2:acc1){
if (acc2.AnnualRevenue>1000){
acc2.adderror('please give lessthan 1000 in annual revenue');
}else if(acc2.AnnualRevenue<1000){
contact con = new contact();
con.AccountId=acc2.Id;
con.LastName=acc2.Name;
con.Phone=acc2.Phone;
conlist.add(con);
}
if(!conlist.isempty()){
insert conlist;
}
}
@isTest
public class test3 {
@testSetUp
public static void method1(){
list <Account> accc = new list <Account>();
Account acc=new Account();
acc.name= 'chinnareddy';
acc.AnnualRevenue=10;
accc.add(acc);
Account acc1=new Account();
acc1.name= 'chinnareddy';
acc1.AnnualRevenue=10000;
accc.add(acc1);
insert accc;
}
@isTest
public static void method2(){
list<Account> acclist= [select Id,name,Phone, AnnualRevenue from Account ];
example3.througherrorinaccount(acclist);
}
}
example 4
}
if(!conlist.isempty()){
insert conlist;
}
}
}
}
@isTest
public class test4 {
@testSetUp
public static void method1(){
Account acc=new Account();
acc.Name= 'chinnareddy';
acc.city__c='Anantapur';
acc.no_of_records__c=3;
insert acc;
}
@isTest
public static void method2(){
list<Account> acclist= [select Id, Name,city__c,no_of_records__c, Phone
from Account];
example4.restrictchildrecord(acclist);
//for(integer i=0;i<6;i++){
Account acc = new Account();
// acc.Name = 'chinnareddy'+i;
//}
}
}