• Biswajit Nath 9
  • NEWBIE
  • 10 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 7
    Questions
  • 3
    Replies
Hi All,

I am trying to optimize a code.
The code uses nested For loop to compare values from new trigger and old trigger. As a result, some time it hits the Apex CPU Time Limit error for a large volume of data.
I would like to ask if there is any better and efficient way to handle this situation.
Many thanks in advance!
 
Hi All,

I want to use the below code to get all the child relationships of an object(both custom and standard):

Schema.DescribeSObjectResult R = Account.SObjectType.getDescribe();
List<Schema.ChildRelationship> C = R.getChildRelationships();

and want to get the object API name of the relationships as a list of strings. I am not able to figure out how to achive this. Could anybody please help?
Hi,
I am trying to use ToolingAPI to fetch Pagelayout informations. As I am using lightning, so I have created
1.connected app:
Connected App
2.Auth Provider:
Auth Provider3.Named Credential:
Named CredentialPlease find below the the code snippet:
Global with sharing class DocGeneration {
    @AuraEnabled 
    public static String Callout(){;
        String resbody;
        Http http = new Http();
        HttpRequest req = new HttpRequest();
        req.setEndpoint('callout:Tooling_API/services/data/v35.0/tooling/query/?q=Select+Id+from+Layout');  
        req.setMethod('GET');
        req.setHeader('Content-Type', 'application/json;charset=UTF-8');
        system.debug('req:' + req);
        HttpResponse res = new HttpResponse();
        res = http.send(req);
        resbody= res.getBody();
        system.debug('res:' + resbody);
        return resbody; 
    }
}
When I am calling this method from annonymous Apex in developer console, It is returning the status as 200 but HTTPResponse has no body.
User-added image
Am I doing anything wrong? Please help.
There is a custom button on account. When it is being clicked it is navigated into a VF page. My requirment is to make a field in the visual force page available or unavailable depending on the type on access the account team member has.For account team member with read/write access will be able to edit that field and those who have only read only can only see the field. Please could anyone help me to achive this? many thanks in advance.
Hi,
I have 200 reports where there is a filter criteria. due to some changes in a third party application from where salesforce is feeded, the filter value needs to be changed for all 200 reports. Is there any shortcut way to update the filter value in one go? Many thanks in advance.
Hi, I have a controller and a VF page where the vf page takes in a csv file and pass it to the controller. The controller follows a particular logic to create user. I am encountering no error but the list named as 'colleaguelist' is not getting populated.

CONTROLLER:
public class importDataFromCSVController {
public Blob csvFileBody{get;set;}
public string csvAsString{get;set;}
public String[] csvFileLines{get;set;}
public List<User> userlist{get;set;}
public List<Colleague_c__c> colleaguelist;
public List<String> Collid{get;set;}

    public importDataFromCSVController(){
        csvFileLines = new String[]{};
        userlist = New List<User>();
        colleaguelist = New List<Colleague_c__c>();
        collid = New List<String>();
    }
  
  public void importCSVFile(){
       
       try{
           csvAsString = csvFileBody.toString();
           csvFileLines = csvAsString.split('\n');
           System.debug('####csv' + csvFileLines);
           
           for(Integer i=1;i<csvFileLines.size();i++){
               String[] csvRecordData =csvFileLines[i].split(',');
               collid.add(csvRecordData[0]);
               
           }
           System.debug('####collid' + collid);
           colleaguelist = [Select Id, Name, IsActive__c, CompanyName__c, Email__c, EmployeeNumber__c from Colleague_c__c where EmployeeNumber__c in:collid];
           System.debug('####colllist' + colleaguelist);   
           for(Integer i=1;i<csvFileLines.size();i++){
           system.debug('###for1 entered');
               string[] csvRecordData = csvFileLines[i].split(',');
            for(Colleague_c__c coll: colleaguelist){
            system.debug('###for2 entered');
            system.debug('###csvRecordData[0]' + csvRecordData[0]);
            system.debug('###coll.EmployeeNumber__c' + coll.EmployeeNumber__c);
            system.debug('###coll.IsActive__c' + coll.IsActive__c);
                    if(csvRecordData[0] == coll.EmployeeNumber__c && coll.IsActive__c == true){
                       system.debug('###if entered');
                       User use = new User() ;
                       use.LastName = coll.Name ;            
                       use.Email = coll.Email__c;
                       use.Username = coll.Email__c;
                       use.CommunityNickname = coll.Name;
                       use.ProfileId = '00e28000001D7DM';
                       use.UserRoleId = '00E28000001lvac';
                       use.EmployeeNumber__c = coll.EmployeeNumber__c;
                       userlist.add(use);  
           }
           }
           
        
           }
           system.debug('####userlist' + userlist);
           insert userlist;
           System.debug('####List inserted');
       }
        
        catch (Exception e)
        {
            ApexPages.Message errorMessage = new ApexPages.Message(ApexPages.severity.ERROR,'An error has occured while importin data Please make sure input csv file is correct');
            ApexPages.addMessage(errorMessage);
         
        }
  } 
  }

VF Page:
<apex:page controller="importDataFromCSVController">
<apex:form >
<apex:pagemessages />
<apex:pageBlock >
<apex:pageBlockSection columns="4">
<apex:inputFile value="{!csvFileBody}" filename="{!csvAsString}"/>
<apex:commandButton value="Import user" action="{!importCSVFile}"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>

Kindly help. Many thanks in advance.
I have  a piece of code where I am getting error at line 3:
public static list<Account> createaccount(Integer numberofrec){
        List<Account> accounts = new list<Account>();
        RecordType recid = New RecordType([Select Id, name From RecordType where sobjecttype = 'Account' and name ='Account_New_Page_Assignment']);
  Colleague__c colleague = new Colleague__c();
  colleague = createcolleague(1)[0];
        for (Integer i = 0; i< numberofrec; i++){
            Account account = new Account(recordtypeid = recid.Id, Name = 'Test Account' + Math.random(), Relationship_Manager__c = colleague.Id , Country__c = 'India - IN' );
   accounts.add(account);
        }
  return accounts;



Can anybody help me out ? Many thanks in advance.
Hi All,

I want to use the below code to get all the child relationships of an object(both custom and standard):

Schema.DescribeSObjectResult R = Account.SObjectType.getDescribe();
List<Schema.ChildRelationship> C = R.getChildRelationships();

and want to get the object API name of the relationships as a list of strings. I am not able to figure out how to achive this. Could anybody please help?
Hi,
I am trying to use ToolingAPI to fetch Pagelayout informations. As I am using lightning, so I have created
1.connected app:
Connected App
2.Auth Provider:
Auth Provider3.Named Credential:
Named CredentialPlease find below the the code snippet:
Global with sharing class DocGeneration {
    @AuraEnabled 
    public static String Callout(){;
        String resbody;
        Http http = new Http();
        HttpRequest req = new HttpRequest();
        req.setEndpoint('callout:Tooling_API/services/data/v35.0/tooling/query/?q=Select+Id+from+Layout');  
        req.setMethod('GET');
        req.setHeader('Content-Type', 'application/json;charset=UTF-8');
        system.debug('req:' + req);
        HttpResponse res = new HttpResponse();
        res = http.send(req);
        resbody= res.getBody();
        system.debug('res:' + resbody);
        return resbody; 
    }
}
When I am calling this method from annonymous Apex in developer console, It is returning the status as 200 but HTTPResponse has no body.
User-added image
Am I doing anything wrong? Please help.
Hi, I have a controller and a VF page where the vf page takes in a csv file and pass it to the controller. The controller follows a particular logic to create user. I am encountering no error but the list named as 'colleaguelist' is not getting populated.

CONTROLLER:
public class importDataFromCSVController {
public Blob csvFileBody{get;set;}
public string csvAsString{get;set;}
public String[] csvFileLines{get;set;}
public List<User> userlist{get;set;}
public List<Colleague_c__c> colleaguelist;
public List<String> Collid{get;set;}

    public importDataFromCSVController(){
        csvFileLines = new String[]{};
        userlist = New List<User>();
        colleaguelist = New List<Colleague_c__c>();
        collid = New List<String>();
    }
  
  public void importCSVFile(){
       
       try{
           csvAsString = csvFileBody.toString();
           csvFileLines = csvAsString.split('\n');
           System.debug('####csv' + csvFileLines);
           
           for(Integer i=1;i<csvFileLines.size();i++){
               String[] csvRecordData =csvFileLines[i].split(',');
               collid.add(csvRecordData[0]);
               
           }
           System.debug('####collid' + collid);
           colleaguelist = [Select Id, Name, IsActive__c, CompanyName__c, Email__c, EmployeeNumber__c from Colleague_c__c where EmployeeNumber__c in:collid];
           System.debug('####colllist' + colleaguelist);   
           for(Integer i=1;i<csvFileLines.size();i++){
           system.debug('###for1 entered');
               string[] csvRecordData = csvFileLines[i].split(',');
            for(Colleague_c__c coll: colleaguelist){
            system.debug('###for2 entered');
            system.debug('###csvRecordData[0]' + csvRecordData[0]);
            system.debug('###coll.EmployeeNumber__c' + coll.EmployeeNumber__c);
            system.debug('###coll.IsActive__c' + coll.IsActive__c);
                    if(csvRecordData[0] == coll.EmployeeNumber__c && coll.IsActive__c == true){
                       system.debug('###if entered');
                       User use = new User() ;
                       use.LastName = coll.Name ;            
                       use.Email = coll.Email__c;
                       use.Username = coll.Email__c;
                       use.CommunityNickname = coll.Name;
                       use.ProfileId = '00e28000001D7DM';
                       use.UserRoleId = '00E28000001lvac';
                       use.EmployeeNumber__c = coll.EmployeeNumber__c;
                       userlist.add(use);  
           }
           }
           
        
           }
           system.debug('####userlist' + userlist);
           insert userlist;
           System.debug('####List inserted');
       }
        
        catch (Exception e)
        {
            ApexPages.Message errorMessage = new ApexPages.Message(ApexPages.severity.ERROR,'An error has occured while importin data Please make sure input csv file is correct');
            ApexPages.addMessage(errorMessage);
         
        }
  } 
  }

VF Page:
<apex:page controller="importDataFromCSVController">
<apex:form >
<apex:pagemessages />
<apex:pageBlock >
<apex:pageBlockSection columns="4">
<apex:inputFile value="{!csvFileBody}" filename="{!csvAsString}"/>
<apex:commandButton value="Import user" action="{!importCSVFile}"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>

Kindly help. Many thanks in advance.