• Pradeep Landge
  • NEWBIE
  • 0 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 6
    Replies
Hello,

I have below code which was workign in Sandbox but on production it fails because records are more than 50000, how can i solve this issue without regression.
public static void PutCodeForAccount( List<Account> accountList ){
Account acc = getLatestAccount();
if(acc != null) {
            Integer intValue = getIntFromName(acc.Code__c);
}

//Method to get the Last inserted Record based on created Date for the existing records
    private static Account getLatestAccount() {
        List<Account> accounts = [SELECT ID, NAME, Code__c  FROM Account ORDER BY CreatedDate Desc];  ///// System.LimitException: Too many query rows: 50001
        if(accounts.size() > 0) {
            return accounts[0];
        }
        return null;
    }

// Method to spilt the first 4 characters from concatinated number
    private static Integer getIntFromName(String Name) {
        String phrase = Name;
        
        Integer rephrase = null;
        
        if(phrase != null && phrase.length() > 4) {
            phrase = phrase.substring(4, phrase.length());
            if(phrase.isNumeric()) {
                rephrase = Integer.valueOf(phrase);
            }
        }
        return rephrase;
    }

The account code(Code__c) lookss like ABCD980001

So the above code takes the integer value of the code from the latest inserted account.

I just want to get the last inserted account

Thanks for help
public static void removeold(Set<Id> oldRecords){

    try{       
       ShareListoAgent = New List<SObject> ();
        ObjectName=new List<Id>(oldRecords).get(0).getSObjectType().getDescribe().getName();
        String queryStr ='select id,UserOrGroupId,parentid,RowCause  from';
        
        if(ObjectName == MemberUpper){
            queryStr = queryStr + ' MemberUpper_Share ';
        }
        if(ObjectName == MemberLower){
            queryStr = queryStr + ' MemberLower_Share ';
        }
        if(ObjectName == 'Account'){
            queryStr = 'select id,UserOrGroupId,AccountId,RowCause  from' + ' AccountShare where AccountId in:oldRecords and RowCause = \'Manual\'';
        }
        if(ObjectName == MemberLower || ObjectName == MemberUpper){
            queryStr = queryStr+'where ParentId in:oldRecords and RowCause = \'Manual\'';
        }
        ShareListoAgent.addAll(Database.query(queryStr));
        //ShareListoAgent = [select id,UserOrGroupId,parentid,RowCause  from MemberUpper_Share where parentid in: oldRecords and RowCause = 'Manual' ];
        system.debug('*******ShareListoAgent*******'+ShareListoAgent);
        if(ShareListoAgent !=null && ShareListoAgent.size()>0){
            delete ShareListoAgent;
        }
      }

 
Hi Guyes,

I have one requirement of custom calender. Here functionality should be as we can add custom holidays as per org and below logic :
Once we select particular date for oppointment, next 4 days shoud be disable.
No one (any user) can select that 4 days for oppointment.

Thanks in Advance !
I have added a button to a page and upon clicking it, I need to navigate to an app in the org. The only information I have found so far on the net is how to navigate to a component. Do the same methods apply to an application (like using "lightning:isUrlAddressable" and pageReference etc.)? Any tips or information would be highly appreciated. Thanks.
is there a way we can optimize these more?
 
public static void checkOpenActivities(List<Case> caseList,Map<Id,Case> caseOldMap) {
        
       List<Case> casedList = New List<Case>();
       List<Task> tskList = new List<Task>();
       integer openActivitiesCount = 0;

       Set<Id> cId = new Set<Id>();
       for(Case cs : caseList) {
            cId.add(cs.Id);
       }
       tskList = [SELECT Id,Status FROM Task Where Status != 'Completed' AND WhatId IN :cId];
        for(Case csNew : caseList) {
            if(tskList.size() != 0 && (csNew.Type__c == 'Question' || csNew.Type__c == 'Information') && csNew.Status == 'Closed') {
                csNew.addError('Can not be closed this');
            }
        }
        
    }

 
this is my visualforce code...
Actually i want to show the loading image button on click of upload attachment  button
On click of select Attachment the apex method is being called which makes the page to rfresh...
i want to avoid the page refresh...
and rerender cannot be used on <apex:inputfile>
////////visualforce code /////////

<apex:page standardController="Account" extensions="extendAccountforstandardController">
<apex:form id="frm">
<apex:pageBlock >
<apex:pageblockSection >
<apex:inputFile value="{!objAttachment.body}" fileName="{!objAttachment.name}"/> 
</apex:pageblockSection>
<apex:pageBlockButtons >
<apex:commandButton value="Select Attachment" action="{!selectAttachment}" rerender="none" />
</apex:pageBlockButtons>
</apex:pageBlock>
<apex:actionRegion >
<apex:pageBlock id="pgBlkId" >
<apex:pageBlockSection >
<apex:inputField value="{!objAccount.parentid}"/>

</apex:pageBlockSection>
<apex:pageBlockButtons >
<apex:outputpanel id="image">
<apex:commandButton action="{!attachRecord}" value=" upload attachment" reRender="image" status="actStatusId" />
</apex:outputpanel>
 <apex:actionStatus id="actStatusId" >
<apex:facet name="start"  >
<img src="/img/loading.gif" />                    
</apex:facet>
</apex:actionStatus> 
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:actionRegion>
</apex:form>
</apex:page>

///// Apex Code

public class extendAccountforstandardController {

    public PageReference attachRecord() {
    
    System.debug('@@objAccount.id'+objAccount.id);
    
     System.debug('@@objAccount.parentId'+objAccount.parentId);
      
      objAttachment.parentId=objAccount.parentId;
      objAttachment.body=bodyAttachment;
      objAttachment.name=nameAttachment;
      
      if(objAccount.parentid!=null){    
        
            insert objAttachment;
        
        }
        return null;
    }

    public blob bodyAttachment;
    
    public string nameAttachment;
    
    public Account objAccount { get; set; }

    public Attachment objAttachment {get; set;}
    
    public extendAccountforstandardController(ApexPages.StandardController controller) {

        objAccount =new Account();
        objAttachment=new Attachment();

    }
    
    public void selectAttachment(){
    bodyAttachment=objAttachment.body;
    nameAttachment=objAttachment.name;
    System.debug(''+'@@nameAttachment'+nameAttachment);
    }
}