• kumar palepu
  • NEWBIE
  • 0 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 8
    Questions
  • 7
    Replies
In below code showing site value is null in debug.kindly help us to resolve the issue.
@isTest
public class testOnUpdation{
static testmethod void Siteupdate()
{
Account aa = new Account (name='istest',RecordTypeId='012j0000000ogEQAAY',Site='istest');
insert aa;
System.Test.startTest();
system.debug('starttest');
Account bb= new Account(name='naugh',RecordTypeId='012j0000000qRATAA2',self__c=aa.id);
insert bb;
system.debug('site'+bb.site);//Here it is showing null value
Account cc=[select Id, name,Site from account where Id =:aa.Id];
cc.Site ='istestchanged' ;
update cc;
update bb;
System.Test.stopTest();
}
 
1. Account has two record type 1.filedreadonly 2.Testing.
2. Same filed but testing record type has look up (self__c) for filedreadonly.
3.  now account site filed which is present is testing is automatically update same name   like as site code which is present is filedreadonly. 
I done with inserting, updating, deleting. Now issue is when I insert the new record in testing. The records is creating  but account site value is not saving.please refer the below code and help me to get out from this problem

trigger testsitevalue on account(after insert,after update,after delete) {

Set <Id>  locationId = new Set<Id>();
Set<Id> filedrecord = new Set<Id>();
Set<Id> totalRecords= new Set<Id>();

list<account> newsite = new list<account> ();

RecordType Vendorlocations;
RecordType FiledRead;
    for (RecordType rt: [SELECT Id, Name, DeveloperName FROM RecordType WHERE RecordType.DeveloperName = 'testing'])
    {
        Vendorlocations = rt;
    }
   
    for (RecordType fr: [SELECT Id, Name, DeveloperName FROM RecordType WHERE RecordType.DeveloperName = 'filedreadonly'])
    {
        FiledRead = fr;
    }
              
  if(avoidRecursive.once)
   {
     avoidRecursive.once= false;
    
     
           if(trigger.isdelete)
           {
           List<account> ac =[select self__c,Site from account where RecordType.Name='testing' AND self__c IN : Trigger.oldMap.keyset() ];
          
            for(account del : ac)
           
            { 
              system.debug('Id'+ del.Id);
              system.debug('ID'+del.self__c);      
              system.debug('sitevalue' +del.site);
             
              del.site='';
              newsite.add(del);
              system.debug('sitevalue'+del.site);
            }
           
            Update newsite; 
           
             System.debug('newsitesize' + newsite.Size());  
          }

      
        //  else if((trigger.isInsert || trigger.isUpdate) && c.RecordTypeId==Vendorlocations.Id)
           
                 
              if (trigger.isInsert || trigger.isUpdate)
               {
                                 
                  for(account c : trigger.new)
                 
                    {
             
                    if(c.RecordTypeId==Vendorlocations.Id)
             
                    {
                    locationId.add(c.self__c);
                   }
         
           }
           
        
    }     
           if (trigger.isInsert || trigger.isUpdate)
               {
                                 
                  for(account z : trigger.new)
                 
                    {
             
                    if(z.RecordTypeId==FiledRead.Id)
             
                    {
                    filedrecord.add(Z.Id);
                   }
         
           }
           
        
    }     


 /*totalRecords.addAll(locationId);
 totalRecords.addAll(filedrecord);
 System.debug('totalsize'+totalRecords.size()); */
system.debug('testingsize'+   locationId.Size()); 
system.debug('FIlereadonlysize'+   filedrecord.Size());      
 Map<Id,String> Sitecodevalue = new Map<Id,String>();
 /*for(account d :trigger.new)
 {
if((trigger.isInsert || trigger.isUpdate) && d.RecordType.Name=='filedreadonly')
  {

   filedrecord.add(d.Id);
  }

else
{ */

//List<account> frecords= [Select Id,Site from  account Where RecordType.Name='filedreadonly'];

for(account i: [Select Id,Site from  account Where RecordType.Name='filedreadonly'])
{
  Sitecodevalue.put(i.Id,i.Site);
}




 System.debug('Map Size' +Sitecodevalue.Size());
 
List< account> location = new List <account>();

for(account p : [Select self__c,Site from account Where RecordType.Name='testing' ])
{
String SitevalueAssign = Sitecodevalue.get(p.self__c);

System.debug('ID'+p.Id);

System.debug('value'+SitevalueAssign);
 
 p.Site = SitevalueAssign;
 location.add(p);
 
}
Update location;

System.debug('listsize' + location.Size());


}

}
In below code showing site value is null in debug.kindly help us to resolve the issue.
@isTest
public class testOnUpdation{
static testmethod void Siteupdate()
{
Account aa = new Account (name='istest',RecordTypeId='012j0000000ogEQAAY',Site='istest');
insert aa;
System.Test.startTest();
system.debug('starttest');
Account bb= new Account(name='naugh',RecordTypeId='012j0000000qRATAA2',self__c=aa.id);
insert bb;
system.debug('site'+bb.site);//Here it is showing null value
Account cc=[select Id, name,Site from account where Id =:aa.Id];
cc.Site ='istestchanged' ;
update cc;
update bb;
System.Test.stopTest();
}
 
1. Account has two record type 1.filedreadonly 2.Testing.
2. Same filed but testing record type has look up (self__c) for filedreadonly.
3.  now account site filed which is present is testing is automatically update same name   like as site code which is present is filedreadonly. 
I done with inserting, updating, deleting. Now issue is when I insert the new record in testing. The records is creating  but account site value is not saving.please refer the below code and help me to get out from this problem

trigger testsitevalue on account(after insert,after update,after delete) {

Set <Id>  locationId = new Set<Id>();
Set<Id> filedrecord = new Set<Id>();
Set<Id> totalRecords= new Set<Id>();

list<account> newsite = new list<account> ();

RecordType Vendorlocations;
RecordType FiledRead;
    for (RecordType rt: [SELECT Id, Name, DeveloperName FROM RecordType WHERE RecordType.DeveloperName = 'testing'])
    {
        Vendorlocations = rt;
    }
   
    for (RecordType fr: [SELECT Id, Name, DeveloperName FROM RecordType WHERE RecordType.DeveloperName = 'filedreadonly'])
    {
        FiledRead = fr;
    }
              
  if(avoidRecursive.once)
   {
     avoidRecursive.once= false;
    
     
           if(trigger.isdelete)
           {
           List<account> ac =[select self__c,Site from account where RecordType.Name='testing' AND self__c IN : Trigger.oldMap.keyset() ];
          
            for(account del : ac)
           
            { 
              system.debug('Id'+ del.Id);
              system.debug('ID'+del.self__c);      
              system.debug('sitevalue' +del.site);
             
              del.site='';
              newsite.add(del);
              system.debug('sitevalue'+del.site);
            }
           
            Update newsite; 
           
             System.debug('newsitesize' + newsite.Size());  
          }

      
        //  else if((trigger.isInsert || trigger.isUpdate) && c.RecordTypeId==Vendorlocations.Id)
           
                 
              if (trigger.isInsert || trigger.isUpdate)
               {
                                 
                  for(account c : trigger.new)
                 
                    {
             
                    if(c.RecordTypeId==Vendorlocations.Id)
             
                    {
                    locationId.add(c.self__c);
                   }
         
           }
           
        
    }     
           if (trigger.isInsert || trigger.isUpdate)
               {
                                 
                  for(account z : trigger.new)
                 
                    {
             
                    if(z.RecordTypeId==FiledRead.Id)
             
                    {
                    filedrecord.add(Z.Id);
                   }
         
           }
           
        
    }     


 /*totalRecords.addAll(locationId);
 totalRecords.addAll(filedrecord);
 System.debug('totalsize'+totalRecords.size()); */
system.debug('testingsize'+   locationId.Size()); 
system.debug('FIlereadonlysize'+   filedrecord.Size());      
 Map<Id,String> Sitecodevalue = new Map<Id,String>();
 /*for(account d :trigger.new)
 {
if((trigger.isInsert || trigger.isUpdate) && d.RecordType.Name=='filedreadonly')
  {

   filedrecord.add(d.Id);
  }

else
{ */

//List<account> frecords= [Select Id,Site from  account Where RecordType.Name='filedreadonly'];

for(account i: [Select Id,Site from  account Where RecordType.Name='filedreadonly'])
{
  Sitecodevalue.put(i.Id,i.Site);
}




 System.debug('Map Size' +Sitecodevalue.Size());
 
List< account> location = new List <account>();

for(account p : [Select self__c,Site from account Where RecordType.Name='testing' ])
{
String SitevalueAssign = Sitecodevalue.get(p.self__c);

System.debug('ID'+p.Id);

System.debug('value'+SitevalueAssign);
 
 p.Site = SitevalueAssign;
 location.add(p);
 
}
Update location;

System.debug('listsize' + location.Size());


}

}