• Kiran kumar 193
  • NEWBIE
  • 30 Points
  • Member since 2015

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 13
    Questions
  • 25
    Replies

trigger Oppsame on Contact(After insert) {

    List <Opportunity> Opp = new List <Opportunity>();

    For (Contact C: Trigger.new){

    Opportunity O = new Opportunity();

   O.Name = C.Name;

    O.CloseDate = System.TODAY();

    O.StageName = 'Closed Won';
     O.AccountId   = C.id;
    Opp.add(O);

    }
 Insert Opp;
}

when we insert contact there will a insert a Opportunity for this contact

its give insert time errror ..
Error: Invalid Data. 
Review all error messages below to correct your data.
Apex trigger Oppsame caused an unexpected exception, contact your administrator: Oppsame: execution of AfterInsert caused by: System.DmlException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, Account ID: id value of incorrect type: 00328000005GxcuAAC: [AccountId]: Trigger.Oppsame: line 18, column 1
 
Hi,
My requirement is is Return date by substracting 2 days from the Priority date and Need to exclude weekends.
If Priority date is
MONDAY (ex: 4/26/2021)- Return last THRUSDAY Date(4/22/2021)
TUESDAY(ex: 4/27/2021)- Return last FRIDAY Date(4/23/2021)
WEDNESDAY(ex: 4/28/2021)- Return MONDAY Date(4/26/2021)
THRUSDAY(ex: 4/29/2021)- Return TUESDAY Date(4/27/2021)
FRIDAY(ex: 4/30/2021)- Return WEDNESDAY Date(4/28/2021)
Below logic is working fine for wednesday,thrusday,friday dates but for monday,tuesday it was returning weekend dates. Appriciate help
CASE(
MOD( DATEVALUE(Priority_Date__c)- DATE(1900, 1, 2), 2),
0, Priority_Date__c-4, 
1, Priority_Date__c-2, 
2, Priority_Date__c-2, 
3, Priority_Date__c+1, 
4, Priority_Date__c+1, 
5,Priority_Date__c+3, 
6,Priority_Date__c+2, 

Priority_Date__c)
Hi All,

I am getting view state error in production environment. it is working in UAT environment. PLease help me to resolve this issue.

"Maximum view state size limit (135KB) exceeded. Actual view state size for this page was 214.36KB"

VF page :
<apex:page sidebar="false" docType="html-5.0" controller="BulkUpload" showHeader="false" >
      
   <apex:form id="form" >

     <apex:sectionHeader title="Upload Carbon Data From CSV File"/>
     
      <apex:pagemessages />
      <apex:pageBlock >
             <!--  Component to allow user to upload file from local machine -->
             
             <center>
             <font color="Blue"> <b>Note: Please <a href="https://drive.google.com/open?id=1BbECRGfkO1oQ5dOTyt0hbmlc9beMnfql5zpZZs" target="_blank"> Click here </a> to follow the instructions for bulkupload csv file. </b> </font> <br/>
             <font color="Blue"> <b>Note: Please use the standard template to upload nova cases. <a href="https://drive.google.com/open?id=0B22fW7Nh4N5BQNTZXM" target="_blank"> Click here </a> to download the template. </b> </font> <br/>
             <font color="Blue"> <b>Note: Please use the standard template to para cases. <a href="https://drive.google.com/open?id=0B22fWk1wS1Jsbms" target="_blank"> Click here </a> to download the template. </b> </font>
             <br/><br/>
             
              <apex:inputFile value="{!contentFile}" filename="{!nameFile}" />
              <font color="Blue"> 
              <apex:commandButton action="{!ReadFile}" value="Upload File" id="theButton" style="width:70px;background:green;font-weight:bold" /></font>
              
             <!-- <br/> <br/> <font color="Blue"> <b>Note: Please use the standard template to upload cases. <a href="https://drive.google.com/file/d/0B5FQvDdE4z0PdFllT1g0aGNBN1k/view?usp=sharing" target="_blank"> Click here </a> to download the template. </b> </font>-->
             </center> 
             
             <br/>
             <div align="center" draggable="false" > 
      <apex:commandButton action="{!cancelPage}" value="Return to HomePage" styleClass="buttonStyle" style="background:green;font-weight:bold"/></div>
                            
          
      </apex:pageBlock>       
   </apex:form>   
</apex:page>

Controller :
public class GAD_CarbonBulkUpload
{
    transient public string nameFile{get;set;}
   transient public Blob contentFile{get;set;}
   transient String[] filelines = new String[]{};
    List<Case> casestoupload;
   // List<String> casestoupload= new List<String>();
    CarbonUtility carbon = new CarbonUtility ();
   transient public static Id carbonRecordtypeId = Schema.SObjectType.Case.getRecordTypeInfosByName().get('Carbon').getRecordTypeId(); 
    public static Map<String, Carbon_Bulk_Vendor__c> Queuemap= Carbon_Bulk_Vendor__c.getAll();
    /***This function reads the CSV file and inserts records into the case object. ***/
    public Pagereference ReadFile()
    {
        try{
                //Convert the uploaded file which is in BLOB format into a string
                nameFile =blobToString( contentFile,'ISO-8859-1');
                
                //Now sepatate every row of the excel file
                filelines = nameFile.split('\n');
                
                //Iterate through every line and create a Account record for each row
                casestoupload = new List<Case>();
                for (Integer i=1;i<filelines.size();i++)
                {
                   transient String[] inputvalues = new String[]{};
                    inputvalues = filelines[i].split(',');
                    
                    Case a= new Case(Status ='New', Origin = 'Web', recordtypeid = carbonRecordtypeId, isparent__c = true, Subject= 'Carbon Implementation', Business_Line__c = 'Carbon Implementation', GAD_Implementation_Type__c = 'Carbon Implementation', Effort_Hours__c=5 );
                    a.Customer_Id__c = inputvalues[0];
                    a.Features__c= inputvalues[2];       
                    a.Language__c = inputvalues[1];
                    a.GAD_Vendor_Name__c = inputvalues[3];
                    if(a.GAD_Vendor_Name__c!= 'BoostMedia' && a.GAD_Vendor_Name__c!='Welocalize' && a.GAD_Vendor_Name__c!='Cognizant'){
                    system.debug('enter into if loop'+ a.GAD_Vendor_Name__c);
                    carbon.setCaseAssignment(a);
                    }
                   
                    if(Queuemap !=null && Queuemap.containsKey(a.GAD_Vendor_Name__c)){
                       a.ownerid = Queuemap.get(a.GAD_Vendor_Name__c).Queue_id__c;
                    }
                    a.Name__c = inputvalues[4];
                    a.Email__c= inputvalues[5];
                    a.Team__c= inputvalues[6];
                    a.Manager__c= inputvalues[7];
                    a.Manager_Email__c= inputvalues[8];
                    a.Location__c= inputvalues[9];
                    a.LDAP__c= inputvalues[10];
                    a.Agency__c = inputvalues[11];
                    a.Name1__c= inputvalues[12];
                    a.AgeEmail__c= inputvalues[13];
                                       
                    casestoupload.add(a);
                    
                }
         }
         catch(Exception e){
                 ApexPages.Message errormsg = new ApexPages.Message(ApexPages.severity.ERROR,'An error has occured reading the CSV file'+e.getMessage());
                ApexPages.addMessage(errormsg);
         }  
         
        /* for(Case c1:casestoupload){
            casestoupload.addall(carbon.setCaseAssignment(c1));
            } */    
        //Finally, insert the collected records
        try{
            insert casestoupload;
            if(casestoupload.size()>0)
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.confirm,'Upload has been successful and cases has been created successfully'));
                        
        }
        catch (Exception e)
        {
            ApexPages.Message errormsg = new ApexPages.Message(ApexPages.severity.ERROR,'An error has occured inserting the records'+e.getMessage());
            ApexPages.addMessage(errormsg);
        }    
        return null;
    }
   
   /**** This function sends back to the visualforce page the list of account records that were inserted ****/ 
   /*public List<Case> getuploadedAccounts()
    {
        if (casestoupload!= NULL)
            if (casestoupload.size() > 0)
            
                return casestoupload;
            else
                return null;                    
        else
            return null;
    } */ 
        /**
         This function convers the input CSV file in BLOB format into a string
        @param input    Blob data representing correct string in @inCharset encoding
        @param inCharset    encoding of the Blob data (for example 'ISO 8859-1')
     */
    public static String blobToString(Blob input, String inCharset){
        String hex = EncodingUtil.convertToHex(input);
        System.assertEquals(0, hex.length() & 1);
        final Integer bytesCount = hex.length() >> 1;
        String[] bytes = new String[bytesCount];
        for(Integer i = 0; i < bytesCount; ++i)
            bytes[i] =  hex.mid(i << 1, 2);
        return EncodingUtil.urlDecode('%' + String.join(bytes, '%'), inCharset);
    }  
     public pagereference cancelPage(){
        Pagereference pageRef = new Pagereference('/apex/HomePage');
        return pageRef;
    }       
}
 
Hi All,

In the Site VF page our internal system pass the URL parameters when they click on a link. salesforce will take the URL parameters and insert a record in salesforce object based on the parameter.

PLease provide if you done this before...
Hi,

I want to insert child records based on parentfield called 'Order Number' on case object and it contains comma separated values. for each and every value i want to insert child for particular parent.
Example:
Parent Case- 1234 -Order number - 123,345,567
child cases for this - 123,345,567

insert three childs here
The code should work for dataload as well (Bulk)
Please help..!
Hi,

I want to insert child records based on parentfield called 'Order Number' on case object and it contains comma separated values. for each and every value i want to insert child for particular parent.
Example:
Order number - 123,345,567

insert three childs here
The code should work for dataload as well (Bulk)
Please help..!
I want to represent attachment name same as the Quote document name
I want to represent Attachment same name Quote document name. These two objects are childs of Quote
I want to update attachment name as opportunity name... Please share the code
I want to update the Attachment name generated by Steelbrick CPQ app under the quote objects. So that salesreps can easily identify the which type of attachment it is... when generating the quote one attachment getting generated and when generating the order one attachment getting generated. Please let me know how do we update attachment name?
On workflow field update I was trying to update the field by using below formula...but I am getting error. Please help on this issue..

Formula :
TEXT(SBQQ__Account__r.Adaptive_Subsidiary_Address__c)

Error: Incorrect parameter type for function 'TEXT()'. Expected Number, Date, DateTime, Picklist, received Text




 
HI Need help on this approach

I have a method Called

private void CreatechildRecords(List<Case> cases, Map<id,Case> oldmap) {
// Existing logic
}

when this method runnung in production we are getting 101 soql query exception.

This method is called from another method called
public void CreateCases(list<Case> newList, list<Case> oldList,map<Id,Case> oldMap)
{
   CreatechildRecords(newlist, oldMap);
}

and this method is calling from trigger by passing context variables. Now My requirement is I want to execute child cases method to be asyncronous. PLease suggest how do I modify the code to support @future annotation.

Please help
I am trying to update the field values from Buttion click on case list page. Button invoking VF page to display the Picklist Dependent fields. We have three fields to update for multiple records.

Type (Pick list) -Required
Subtype (picklist) - Required
Totalsubtype(Multiselect Picklist) - Not required

First two fileds are updating correctly but Multi select picklist is storing previous value if the current record value is null when try to update the records. If there is no value in the multiselect field I need to update as blank.

Please suggest the solution... I need it urgently
Controller :
public class CaseUpdate
{
   private final List<Case> cases;
   public boolean isErrorOccured{get;set;} 
           
   public ESDJC_CaseUpdate(ApexPages.StandardSetController standardController)
   {
      
     this.cases = [select Id,Topic__c,RecordType.Name,Sub_Topic__c,Type from case where id in : standardController.getSelected()];
     
    
   }
   public PageReference cancel(){
        PageReference returnPage = new PageReference(ApexPages.currentPage().getParameters().get('retURL'));
        return returnPage;
    }
    public PageReference validateOnLoad(){
    
         if(cases == null || cases.size() == 0 ){
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Please select at least one record.'));
            isErrorOccured = true;
            
            return null;
        }
        
       
      return null;  
   }
  
  
   }
 
VF page:

<apex:page standardController="Case" recordSetVar="Cases" extensions="CaseUpdate" action="{!validateOnLoad}">
<html xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">  
        <head>
            <apex:stylesheet value="{!URLFOR($Resource.SLDS090, 'assets/styles/salesforce-lightning-design-system-vf.css')}" />
        </head>
     <body>     
    <div class="slds">
    <apex:form id="theForm" >
  <apex:pageMessages id="messages"/>
        <apex:pageBlock mode="edit" id="pb">
            <apex:pageBlockButtons >
                <apex:commandButton styleClass="slds-button slds-button--neutral" action="{!Save}" value="Save" rerender="messages"  rendered="{!!isErrorOccured}"/>
                <apex:commandButton styleClass="slds-button slds-button--neutral" value="Cancel" action="{!cancel}"/>
            </apex:pageBlockButtons>
            
            <apex:pageBlockSection title="Case Information" columns="1">
            <apex:inputField value="{!Case.Type}"/>
            <apex:inputField value="{!Case.Topic__c}" />
            
            <apex:inputField value="{!Case.Sub_Topic__c}" >
          
           
            </apex:inputField>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
    </div>
    </body>
    </html>
</apex:page>
Soultion Urgent.............!

Enable send Email Notifications Checkbox by default for Specific queues... on Case when changing the owner of the case

Only for these queues shoulld be enabled by default and not other queues

Queue 1
Queue 1

Please suggest the solution...........
Regards,
kk

 
My requirement was Latest opportunity name should be displayed in account object custom field.

Getting null pointer exception when I delete the opportunity for the Account. How do we handle this error.

Class :

public class OppAccUpdate
{
  
  public void oppupdate(List<opportunity> oplist)
  {
      
    set<id> accid = new set<id>();
    
   // List<Account> acctoUpdate= new List<Account>();
   
   Map<id,Account> mapaccounts = new Map<id,Account>();
    
    for(opportunity opp:oplist)
    {
       accid.add(opp.Accountid);
    }
    List<Account> acc =[select id, oppname__c,(select id, name from opportunities order by createddate) from Account where id in:accid];
    system.debug('****Thesize of account***'+acc.size());
    system.debug('****The oppname***'+acc[0].oppname__c);
    system.debug('****The opportunity***'+acc[0].opportunities);
    for(Account a:acc)
    {
       for(opportunity o:a.Opportunities)
       {
          if(a.oppname__c==null || (a.oppname__c!=o.Name))
          {
          system.debug('***inside for loop***'+ a.oppname__c);
          system.debug('***inside for loop111***'+ o.name);
          a.oppname__c = o.Name;
          mapaccounts.put(a.id,a);
         // acctoUpdate.add(a);
          }
       }
    }
    if(!mapaccounts.isEmpty())
    update  mapaccounts.values();

      
  }
}

Trigger:

trigger oppaccupdate on Opportunity (after insert, After update, After delete) 
{
     Opportunity[] opp = trigger.new;
     
     if(trigger.isInsert || trigger.isAfter)
     {
       OppAccUpdate ou = new OppAccUpdate();
       ou.oppupdate(opp);
     }
     
      if(trigger.isUpdate || trigger.isAfter)
     {
       OppAccUpdate ou = new OppAccUpdate();
       ou.oppupdate(opp);
     }
     
      if(trigger.isDelete || trigger.isAfter)
     {
       Opportunity[] opp1 = trigger.old;
       OppAccUpdate ou = new OppAccUpdate();
       ou.oppupdate(opp1);
     }
}
Hi,
My requirement is is Return date by substracting 2 days from the Priority date and Need to exclude weekends.
If Priority date is
MONDAY (ex: 4/26/2021)- Return last THRUSDAY Date(4/22/2021)
TUESDAY(ex: 4/27/2021)- Return last FRIDAY Date(4/23/2021)
WEDNESDAY(ex: 4/28/2021)- Return MONDAY Date(4/26/2021)
THRUSDAY(ex: 4/29/2021)- Return TUESDAY Date(4/27/2021)
FRIDAY(ex: 4/30/2021)- Return WEDNESDAY Date(4/28/2021)
Below logic is working fine for wednesday,thrusday,friday dates but for monday,tuesday it was returning weekend dates. Appriciate help
CASE(
MOD( DATEVALUE(Priority_Date__c)- DATE(1900, 1, 2), 2),
0, Priority_Date__c-4, 
1, Priority_Date__c-2, 
2, Priority_Date__c-2, 
3, Priority_Date__c+1, 
4, Priority_Date__c+1, 
5,Priority_Date__c+3, 
6,Priority_Date__c+2, 

Priority_Date__c)
Hi All,

In the Site VF page our internal system pass the URL parameters when they click on a link. salesforce will take the URL parameters and insert a record in salesforce object based on the parameter.

PLease provide if you done this before...
Hi,

I want to insert child records based on parentfield called 'Order Number' on case object and it contains comma separated values. for each and every value i want to insert child for particular parent.
Example:
Order number - 123,345,567

insert three childs here
The code should work for dataload as well (Bulk)
Please help..!
I want to update attachment name as opportunity name... Please share the code
On workflow field update I was trying to update the field by using below formula...but I am getting error. Please help on this issue..

Formula :
TEXT(SBQQ__Account__r.Adaptive_Subsidiary_Address__c)

Error: Incorrect parameter type for function 'TEXT()'. Expected Number, Date, DateTime, Picklist, received Text




 
HI Need help on this approach

I have a method Called

private void CreatechildRecords(List<Case> cases, Map<id,Case> oldmap) {
// Existing logic
}

when this method runnung in production we are getting 101 soql query exception.

This method is called from another method called
public void CreateCases(list<Case> newList, list<Case> oldList,map<Id,Case> oldMap)
{
   CreatechildRecords(newlist, oldMap);
}

and this method is calling from trigger by passing context variables. Now My requirement is I want to execute child cases method to be asyncronous. PLease suggest how do I modify the code to support @future annotation.

Please help
Soultion Urgent.............!

Enable send Email Notifications Checkbox by default for Specific queues... on Case when changing the owner of the case

Only for these queues shoulld be enabled by default and not other queues

Queue 1
Queue 1

Please suggest the solution...........
Regards,
kk