• ankaiah bandi 6
  • NEWBIE
  • 0 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 2
    Replies
@RestResource(urlMapping='/sfdcCallingContact/*')
global class GetContactFromUKOrg{


@HttpPost
  global static String insertContact()
  {
    System.debug('entered..'+RestContext.request.requestBody.toString().trim());
    String jsonBody = RestContext.request.requestBody.toString().trim();
    System.debug('jsonBody'+jsonBody );
     
  
    List<Contact> ConObj = (List<Contact>)JSON.deserialize(jsonBody,List<Contact>.class);
      
       List<Contact> ConObjInsert = new List<Contact>();
       List<Contact> ConObjUpdate = new List<Contact>();
        
   
   Iterator<Contact> keys = ConObj.iterator();
              while(keys.hasNext()){
                  Contact key = keys.next();
                 if(key.Id != null){
                       ConObjUpdate.addAll(Conobj);
                 }else {
                       ConObjInsert.addAll(ConObj);
                 }
            }
      try{
          if(ConObjUpdate != null){
              update ConObjUpdate;
          }
          if(ConObjInsert != null){
              insert ConObjInsert;
              return JSON.serialize(ConObjInsert);
          }   
      }catch(Exception e){
         return JSON.serialize('Error while creating Contact');
      } 
          
          
     return 'Success';
  }
  
 
  
}
Hi,

i need to display the count of child records for custom object called "Network__c", which have the  selflookup lookup realtionship.the Network__c can have 3 recordtypes called A ,B &C... here A is parent of B recordtype and B is parent of C record type..Now my expected scenario is, i need to displsy
1. the count of B records and C records at A recordtype level.
2. the count of C records at B recordtype level.
Note: here at B recordtype level and C record type level have the same lookup relationship field name called parent__c. at B recordtype level we need to select only A record type and at C record type level we need to select only B record type.
problem : i am not able display the count of C records at A record type level.

Now i can have error to display count of C records,please see the below code  and can any one help me how can i proceed? 
error message: "initial term of field expression must be a concrete SObject: Map&lt;Id,Network__c&gt;"

trigger Countofchilds on Network__c (before insert, before update, before delete) {
    
    Map<Id,Network__c> Amap_Ids = new Map<Id,Network__c>();
    Map<Id,Network__c> Bmap_Ids = new Map<Id,Network__c>();
    Map<Id,Network__c> Cmap_Ids = new Map<Id,Network__c>();
    if(Trigger.isUpdate || Trigger.isInsert){
        Amap_Ids=getTypeofNtw.groupNtw(Trigger.New);
        Bmap_Ids=getTypeofNtw.MNtw(Trigger.New);
        Cmap_Ids=getTypeofNtw.ONtw(Trigger.New);
    }
    if(!Amap_Ids.isEmpty() && (Trigger.isUpdate || Trigger.isInsert)){
        Map<Id,Network__c> lnpp =new Map<Id,Network__c>( [SELECT Id,Number of C__c,Number of B__C,(Select id from Parent__r) FROM Network__c WHERE Id IN: Amap_Ids.keySet()] );

        Set<Id> MNppset = new Set<Id>();
        for(Id i : lnpp.keyset()){
            Network__c np = lnpp.get(i);
            for(Network__c n : np.Parent__r){
                MNppset.add(n.Id);
            }
        }
        Map<Id,Network__c> mnpp =new Map<Id,Network__c>( [SELECT Id,(Select id from Parent__r) FROM Network__c WHERE Id IN: MNppset] );
        for(Id i : lnpp.keyset()){
            Network__c np = lnpp.get(i);            
            try{
                system.debug('------>'+np.Parent__r.size());
                if(!np.Parent__r.isEmpty())   
                    Amap_Ids.get(i).Number of B__C=np.Parent__r.size();
               for(Network__c n : np.Parent__r){
                    if(!mnpp.Parent__r.isEmpty()) 
                        Amap_Ids.get(i).Number of C__c  =Amap_Ids.get(i).Number of C__c+1; 
                }
            }catch(Exception e){
                Amap_Ids.get(i).Number of B__C=0;
            }    
        }        
    }                   
 }//End
 
can any one provide the code for the above requirement, it would be greatfull......Thanks.....!!!!


 
All leads received in SFDC from Digitas and sent to Siebel and updates for all leads received from Siebel, if they have been successfully loaded or rejected in SFDC. Creation of error log providing the details as in the generic template. This error log can be of the format CSV. can any one help me on this scenario.
@RestResource(urlMapping='/sfdcCallingContact/*')
global class GetContactFromUKOrg{


@HttpPost
  global static String insertContact()
  {
    System.debug('entered..'+RestContext.request.requestBody.toString().trim());
    String jsonBody = RestContext.request.requestBody.toString().trim();
    System.debug('jsonBody'+jsonBody );
     
  
    List<Contact> ConObj = (List<Contact>)JSON.deserialize(jsonBody,List<Contact>.class);
      
       List<Contact> ConObjInsert = new List<Contact>();
       List<Contact> ConObjUpdate = new List<Contact>();
        
   
   Iterator<Contact> keys = ConObj.iterator();
              while(keys.hasNext()){
                  Contact key = keys.next();
                 if(key.Id != null){
                       ConObjUpdate.addAll(Conobj);
                 }else {
                       ConObjInsert.addAll(ConObj);
                 }
            }
      try{
          if(ConObjUpdate != null){
              update ConObjUpdate;
          }
          if(ConObjInsert != null){
              insert ConObjInsert;
              return JSON.serialize(ConObjInsert);
          }   
      }catch(Exception e){
         return JSON.serialize('Error while creating Contact');
      } 
          
          
     return 'Success';
  }
  
 
  
}
My requirement was to look for all the records deleted by a particular user spanning mulitple objects and delete those records from recycle bin. I tried to come up with this code and it worked, but when there is too much of data it hits Apex governor limit. I am new to coding and don't know how to circumvent that. I initially tried writing my query in start method but I was not able to query multiple objects there using for loop.

I am using custom setting (EmptyRecycleBinBatch) to hold object API names.. Any suggestion is appreciated!

global class EmptyRecycleBinBatch implements Database.Batchable<sObject>, Schedulable {

    global Database.QueryLocator start(Database.BatchableContext BC) {
        String Query='Select Id, ObjectAPIName__c From EmptyRecycleBinBatch__c';
         return database.getquerylocator(Query);
   }

    global void execute(Database.BatchableContext BC,List<EmptyRecycleBinBatch__c> sObjRecords) {
        System.debug('in execute method');
        User userid= [Select Id, Name from User where User.Name= ' test user' And isActive= true Limit 1];
        String Query;
        
        for(EmptyRecycleBinBatch__c sOb: sObjRecords){ 
        
        SYstem.debug('object name :'+sOb.ObjectAPIName__c); 
          Query = 'SELECT ID from '+sOb.ObjectAPIName__c+' where isDeleted = true AND CreatedById = \''+userid.Id+'\' all rows';
        system.debug('query '+Query );            
        List<Sobject> sObjtocreate = new List<Sobject>();    
        sObjtocreate = Database.query(Query);
            System.debug('list of items to delete'+sObjtocreate);
      if(sObjtocreate != null && !sObjtocreate.isEmpty()) { 
          
     try{
         //system.debug(' deleting :'+sObjtocreate);
           Database.emptyRecycleBin(sObjtocreate); 
            if(test.isRunningTest())
            {
                 throw new applicationException('Exception');
            }
        }
        catch(Exception e){
            System.debug('ERROR on Delete:' + e);
        }
       }
      }
     }     
    public class applicationException extends Exception 
    {
    
    } 
    global void finish(Database.BatchableContext BC) {
        
    }
    global void execute(SchedulableContext sc) {
        database.executebatch(new EmptyRecycleBinBatch());
    }
}