• Shaik Naga jani
  • NEWBIE
  • 225 Points
  • Member since 2018

  • Chatter
    Feed
  • 7
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 21
    Replies

Hi all ,

I am creating an apex trigger(before insert,before update) to add the amount of opportunities created by a single user should not exceed n 1000 a single day. I have successfully created for inserting..

But for updating ,while taking sum it is adding the both the record to be updated's existing value and new to be updated value , which it shouldnt be doing and should take only the new updated value for calculating.

so i wrote a if loop with contains , but i am getting compiler error .Please help

list<opportunity> op2= [Select id,name,amount from opportunity where CreatedByID = :UserInfo.getUserId() and createdDate = TODAY];
     decimal sum=0.0;
    // Query for adding existing opportunity amount
   
    if( op2.size() > 0)
    {
        for (opportunity o : op2)
        {
             if(op1.contains(o.id) == 1)
             {
                 sum=sum+o.amount;
                 System.debug('records loop');
             }
        }
    }

error: Compile Error: Method does not exist or incorrect signature: void contains(Id) from the type List<Opportunity> at line 17 column 21

please let me know what i am doing wrong.

Thanks in advance

Hello All,
As a newbee, trying to debug Account Name of Cases whose status = NEW with the help of Case.AccountID in logs the following:
My approach is as below:
public class NewCaseListController {

    public List<Case> getNewCases()
    {
        String n = 'NEW';
        List<Case> results = [SELECT ID, 
                              CaseNumber, 
                              Status ,
                              AccountId    
                              from CASE
                              WHERE Status=:n];
        System.debug(results.size());
        for(Case c : results)
        {
         System.debug('CASE ID = '+ c.Id); 
         System.debug('CASE NUMBER = '+ c.CaseNumber);
         System.debug('Account ID = '+ c.AccountId);
         System.debug('CASE STATUS = '+ c.Status);
        }

        return results;
    }
}

My attempt failed.
Can I get Account Name using AccountID of a CASE? If so, Please please do enlighten how this can be done?

Thanks in Advance.
-LS
User-added imageI have a requirement to select an object from the list and then select the required fields. Once I click query it has to generate an SOQL query for that select fields. I did it but it is coming with brackets like in the above image. Please help me to fix the issue. 

My Method is: 
  public void query(){
    map<integer,string> strl = new map<integer,string>();
    for(integer i=0 ; i<getfields.size(); i++){
    strl.put(i,getfields[i]);
    }
    system.debug('strl===>' +strl);
    inputrec = 'select   '+strl.values()+' from ' +strObjectName;
    }


Thank you in advance. 
Regards, 
Sujendran. 
 
I wrote a fairly simple trigger on the ContentVersion object which ultimately would allow tracking opportunities without a signed contract. 

So a document is added or changed and the picklist value 'Signed Contract' is selected. This would flip the 'HasSignedQuote__c' bollean on true on the opportunity. 

However I noticed that the LinkedEntityId from the ContentDocumentLink is not always populated and I can't get my finger behind the root cause.
 
trigger ContentVersion_TRIGGER on ContentVersion (After insert, After update) {

      
    Public static Boolean SignedContract = false;

    System.debug(LoggingLevel.Info,'[ContentVersion_TRIGGER]. - TRIGGER ');
    

        Set<Id> contentDocumentIdSet = new Set<Id>();
        for(ContentVersion cv:trigger.new){

            if(cv.ContentDocumentId != null){
                contentDocumentIdSet.add(cv.ContentDocumentId);
                If(cv.File_Type__c == 'Signed Contract'){ //** Based on Content version picklist ...
                   System.debug(LoggingLevel.Info,'[ContentVersion_TRIGGER]. - Set SignedContract = true');   
                   SignedContract = true;
                }
            }
        }
        System.debug(LoggingLevel.Info,'[ContentVersion_TRIGGER].contentDocumentIdSet'+contentDocumentIdSet);   
        ContentDocumentLink cdl = [SELECT ContentDocumentId, LinkedEntityId FROM ContentDocumentLink WHERE ContentDocumentId IN:contentDocumentIdSet Limit 1];
        System.debug(LoggingLevel.Info,'[ContentVersion_TRIGGER].ContentDocumentLink  :'+cdl.LinkedEntityId);      
        List<Opportunity> OppList = [SELECT Id, HasSignedQuote__c FROM Opportunity where Id =:cdl.LinkedEntityId];  
        System.debug(LoggingLevel.Info,'[ContentVersion_TRIGGER].OppList.size() :'+OppList.size());  
        For (Opportunity Opp:OppList){
            If (SignedContract == true){
                System.debug(LoggingLevel.Info,'[ContentVersion_TRIGGER]. - Flag opportunity HasSignedQuote to true ...');   
                Opp.HasSignedQuote__c = true;
            }
        }
        Update OppList;
   
} //** end of Class

 
hi

From process builder can we call an apex class which has a method to create a record in a object ?

Hi, 
I have a requirement as once the objectname is selected from the selectlistoptions it has to display all its field names. I am trying to acheive this but the actionsupport is not calling the method in action(action="{!getfieldnames}").Please help. 

VF page: 
<apex:page controller="Workbenchlike" >
<style>
td{
text-align:center;
}
</style>
<apex:form >

<div style="text-align:center;font-size:20px">

    Select from the list  :-
<apex:outputPanel >
<apex:selectList size="1" value="{!selectedobj}" >
<apex:selectOptions value="{!selectobjs}"/>
<apex:actionSupport action="{!getfieldnames}" event="onchange"  reRender="table"/>

</apex:selectList>
</apex:outputPanel>
</div>
<div style="text-align:center; font-size:15px">
<table id="table" >
<tr> 
<td>
FieldNames:<br/>
<apex:selectList ></apex:selectList>
</td>
<td>
Selected Values:<br/>
<apex:selectList ></apex:selectList>
</td>
</tr>
</table>
</div>
  </apex:form>
</apex:page>

Controller: 

public class Workbenchlike {
public string selectedobj {get; set;}
public map<string, schema.sobjectType> selectobjs {get; set;}

public workbenchlike(){
selectobjs = schema.getGlobalDescribe();
system.debug('output is'+selectobjs);
system.debug('selectedobject' +selectedobj);
}
public void getfieldnames(){
system.debug('selectedobject' +selectedobj);

}

}

Thank you. 
Regards, 

Sujendran.

Hi,
I had a simple field validation rule that required a comment when a particular status was set (this would normally be when my auto logic was in progress). I've now had to change the validation so that when a new item is added the status can be manually set, and require a comment.

This is the rule I have but it raises an alert all the time preventing the new recorded from being saved. Any ideas?
 

Thanks!

AND( 
ISPICKVAL(Status__c , 'Authorised'), 
AND 
(NOT(ISCHANGED( ITK_Comments__c ))) 
|| 
ISBLANK(ITK_Comments__c) 
|| 
ISNEW() 
)


 
Hi,
I am trying to pass the values from apex controller to visualforce page for radio buttons. Then i want to pass back the selected value in the controller. can anybody please help. The code written so far 
Visualforce page 



 <apex:repeat value="{!optionsListvf}" var="s">
                <apex:selectRadio >
                    <apex:selectOption > {!s} </apex:selectOption>
                </apex:selectRadio>
            </apex:repeat>




Apex class 

 public List<string> optionsListvf {get;set;}
    
    Public static String buttonbehaviourvf{get;set;}
    
    public  QuestionAnswerController(){
        String question =apexpages.currentpage().getparameters().get('question');
        String optionsList=apexpages.currentpage().getparameters().get('optionsList');
        String buttonbehaviour = apexpages.currentpage().getparameters().get('buttonbehaviour');
        questionvf=question;
        String finalOptions =  optionsList.replace('(','').replace(')','');
        optionsListvf=finalOptions.split(',');
        buttonbehaviourvf=buttonbehaviour;
        
    }

 
  • September 12, 2019
  • Like
  • 0
Hi All,

I am new to developing and give me some insights how to upload csv file using LWC .

Regard,
Siva 
I have written a code to attach multiple attachment from vf page using forcetk.
The code is working fine when I am running the VF page individually
but when I am attaching the VF page in Salesforce Site the file is not attaching and its giving INVALID_SESSION_ID.

Is there any way to get SessionID in Salesfore Site.
Can anyone help..??
Could you any please let me know how to get the logfile from eventlog and sent it to execute method

global class batchEventLog implements Database.Batchable<sObject> {


    list<string> headersList{get;set;}
    Set<String> csvHeader = new Set<String>();
    String combinedDataAsHex = '';
    Blob combinedDataAsBlob;
    String csvFileData ='';
    String userEmail ='';
    String newSetStr = '' ; 
    List<String> newSetStrList = new List<String>();
    String noOfDays = '';
    Set<String> strEventTypes = new Set<String>();
   // HttpRequest req = new HttpRequest();
    public list<String> eventTypelist = new list<String>();
    
    
    
    
   
    global Database.QueryLocator start(Database.BatchableContext BC) {
    
    
    System.debug('I am inside the start method');
    
    List<String> eventTypesArr = new List<String>();
        List<Event_Log_File_Configuration__mdt> eventconf = new List<Event_Log_File_Configuration__mdt>([SELECT Event_Types__c, Duration_in_days__c, User_Email__c FROM Event_Log_File_Configuration__mdt where DeveloperName = 'Event_Log' limit 1]);
        userEmail = eventconf[0].User_Email__c;
        noOfDays =  eventconf[0].Duration_in_days__c;
        String eventTypes = eventconf[0].Event_Types__c;
        if(eventTypes.contains(',')){
            eventTypesArr = eventTypes.split(',');
        }
        else{
            eventTypesArr.add(eventTypes);
        }
        for(String evStr : eventTypesArr){
            strEventTypes.add(evStr);
        }
    
     for(String evStr : eventTypelist){
            strEventTypes.add(evStr);
        } 

       System.debug('::::Event Type Values::::' + strEventTypes);
        for(String str : strEventTypes){
            newSetStr += '\'' + str + '\',';
        
       newSetStr = newSetStr.lastIndexOf(',') > 0 ? '(' + newSetStr.substring(0,newSetStr.lastIndexOf(',')) + ')' : newSetStr ;
        }
       System.debug('***************The value of newSetStr is '+newSetStr); 
       newSetStrList.add(newSetStr);
        system.debug('**********************newSetStrList'+newSetStrList);
  
      String query = 'Select Id,LogFile,EventType from EventLogFile';
    
      //  Blob s = 'Select Id,LogFile,EventType from EventLogFile';
        
  //      string query = b.tostring();
          //query = EncodingUtil.base64Decode(EncodingUtil.base64Encode(b)).toString();

        return Database.getQueryLocator(query);
    }
   
    global void execute(Database.BatchableContext BC, List<EventLogFile> scope) {
    
          System.debug('Iam inside the execute method');
         for(EventLogFile a : scope)
         {
             System.debug('The value of event log  file'+a.EventType);
             System.debug('The value of log file is '+a.LogFile);
                         
         }
        
    }   
    
    global void finish(Database.BatchableContext BC) {
    }
}
HI All,


Please solve the problem 
how to prevent the more then one attachement on parent record ?



Thanks 
aklkk
  • February 25, 2019
  • Like
  • 0

Hi all ,

I am creating an apex trigger(before insert,before update) to add the amount of opportunities created by a single user should not exceed n 1000 a single day. I have successfully created for inserting..

But for updating ,while taking sum it is adding the both the record to be updated's existing value and new to be updated value , which it shouldnt be doing and should take only the new updated value for calculating.

so i wrote a if loop with contains , but i am getting compiler error .Please help

list<opportunity> op2= [Select id,name,amount from opportunity where CreatedByID = :UserInfo.getUserId() and createdDate = TODAY];
     decimal sum=0.0;
    // Query for adding existing opportunity amount
   
    if( op2.size() > 0)
    {
        for (opportunity o : op2)
        {
             if(op1.contains(o.id) == 1)
             {
                 sum=sum+o.amount;
                 System.debug('records loop');
             }
        }
    }

error: Compile Error: Method does not exist or incorrect signature: void contains(Id) from the type List<Opportunity> at line 17 column 21

please let me know what i am doing wrong.

Thanks in advance

Hello All,
As a newbee, trying to debug Account Name of Cases whose status = NEW with the help of Case.AccountID in logs the following:
My approach is as below:
public class NewCaseListController {

    public List<Case> getNewCases()
    {
        String n = 'NEW';
        List<Case> results = [SELECT ID, 
                              CaseNumber, 
                              Status ,
                              AccountId    
                              from CASE
                              WHERE Status=:n];
        System.debug(results.size());
        for(Case c : results)
        {
         System.debug('CASE ID = '+ c.Id); 
         System.debug('CASE NUMBER = '+ c.CaseNumber);
         System.debug('Account ID = '+ c.AccountId);
         System.debug('CASE STATUS = '+ c.Status);
        }

        return results;
    }
}

My attempt failed.
Can I get Account Name using AccountID of a CASE? If so, Please please do enlighten how this can be done?

Thanks in Advance.
-LS
User-added imageI have a requirement to select an object from the list and then select the required fields. Once I click query it has to generate an SOQL query for that select fields. I did it but it is coming with brackets like in the above image. Please help me to fix the issue. 

My Method is: 
  public void query(){
    map<integer,string> strl = new map<integer,string>();
    for(integer i=0 ; i<getfields.size(); i++){
    strl.put(i,getfields[i]);
    }
    system.debug('strl===>' +strl);
    inputrec = 'select   '+strl.values()+' from ' +strObjectName;
    }


Thank you in advance. 
Regards, 
Sujendran. 
 
Hello Folks,

Below is the sample code :
Map<Id, Lead> ledMap = //Consider this will give me 3 records
for(Lead l : leadMap.values()){
if(l.status = 'New'){
//logic here
}
else if(l.status = 'Dead'){
//logic here
}
}

What I am looking at here is, if any record meet the first creteria (l.status = 'New') then I don't want to iterate the remaining records (in this case remaining 2 records). And in case if none of the records meet the first creteria (l.status = 'New') then only I need to perform the logic inside the else if condition. 

Looking forward for your inputs.

Thanks,
Shravan
 
I wrote a fairly simple trigger on the ContentVersion object which ultimately would allow tracking opportunities without a signed contract. 

So a document is added or changed and the picklist value 'Signed Contract' is selected. This would flip the 'HasSignedQuote__c' bollean on true on the opportunity. 

However I noticed that the LinkedEntityId from the ContentDocumentLink is not always populated and I can't get my finger behind the root cause.
 
trigger ContentVersion_TRIGGER on ContentVersion (After insert, After update) {

      
    Public static Boolean SignedContract = false;

    System.debug(LoggingLevel.Info,'[ContentVersion_TRIGGER]. - TRIGGER ');
    

        Set<Id> contentDocumentIdSet = new Set<Id>();
        for(ContentVersion cv:trigger.new){

            if(cv.ContentDocumentId != null){
                contentDocumentIdSet.add(cv.ContentDocumentId);
                If(cv.File_Type__c == 'Signed Contract'){ //** Based on Content version picklist ...
                   System.debug(LoggingLevel.Info,'[ContentVersion_TRIGGER]. - Set SignedContract = true');   
                   SignedContract = true;
                }
            }
        }
        System.debug(LoggingLevel.Info,'[ContentVersion_TRIGGER].contentDocumentIdSet'+contentDocumentIdSet);   
        ContentDocumentLink cdl = [SELECT ContentDocumentId, LinkedEntityId FROM ContentDocumentLink WHERE ContentDocumentId IN:contentDocumentIdSet Limit 1];
        System.debug(LoggingLevel.Info,'[ContentVersion_TRIGGER].ContentDocumentLink  :'+cdl.LinkedEntityId);      
        List<Opportunity> OppList = [SELECT Id, HasSignedQuote__c FROM Opportunity where Id =:cdl.LinkedEntityId];  
        System.debug(LoggingLevel.Info,'[ContentVersion_TRIGGER].OppList.size() :'+OppList.size());  
        For (Opportunity Opp:OppList){
            If (SignedContract == true){
                System.debug(LoggingLevel.Info,'[ContentVersion_TRIGGER]. - Flag opportunity HasSignedQuote to true ...');   
                Opp.HasSignedQuote__c = true;
            }
        }
        Update OppList;
   
} //** end of Class

 
hi

From process builder can we call an apex class which has a method to create a record in a object ?

Hi, 
I have a requirement as once the objectname is selected from the selectlistoptions it has to display all its field names. I am trying to acheive this but the actionsupport is not calling the method in action(action="{!getfieldnames}").Please help. 

VF page: 
<apex:page controller="Workbenchlike" >
<style>
td{
text-align:center;
}
</style>
<apex:form >

<div style="text-align:center;font-size:20px">

    Select from the list  :-
<apex:outputPanel >
<apex:selectList size="1" value="{!selectedobj}" >
<apex:selectOptions value="{!selectobjs}"/>
<apex:actionSupport action="{!getfieldnames}" event="onchange"  reRender="table"/>

</apex:selectList>
</apex:outputPanel>
</div>
<div style="text-align:center; font-size:15px">
<table id="table" >
<tr> 
<td>
FieldNames:<br/>
<apex:selectList ></apex:selectList>
</td>
<td>
Selected Values:<br/>
<apex:selectList ></apex:selectList>
</td>
</tr>
</table>
</div>
  </apex:form>
</apex:page>

Controller: 

public class Workbenchlike {
public string selectedobj {get; set;}
public map<string, schema.sobjectType> selectobjs {get; set;}

public workbenchlike(){
selectobjs = schema.getGlobalDescribe();
system.debug('output is'+selectobjs);
system.debug('selectedobject' +selectedobj);
}
public void getfieldnames(){
system.debug('selectedobject' +selectedobj);

}

}

Thank you. 
Regards, 

Sujendran.

Hi,
I had a simple field validation rule that required a comment when a particular status was set (this would normally be when my auto logic was in progress). I've now had to change the validation so that when a new item is added the status can be manually set, and require a comment.

This is the rule I have but it raises an alert all the time preventing the new recorded from being saved. Any ideas?
 

Thanks!

AND( 
ISPICKVAL(Status__c , 'Authorised'), 
AND 
(NOT(ISCHANGED( ITK_Comments__c ))) 
|| 
ISBLANK(ITK_Comments__c) 
|| 
ISNEW() 
)


 
HIi can any one please solve my problem,Below I have placed the code
Thanks in advance,any support is appreciated.

<apex:page standardController="OpportunityLineItem" extensions="scheduleOptyProd" docType="html-5.0" sidebar="true" showHeader="true" standardStylesheets="true" cache="true">
    
    
    <script> 
    // JavaScript function to check the value entered in the inputField
    function validation() 
    {
        alert('test');
        var val = document.getElementById('{!$Component.fm.tabledata.pbl.pblt.qq}').value;
        alert('val:'val);
        if (val == null || val == '') 
        {
            alert('val is '+val);
        }
        else alert('Please enter some text');
        
    }
    </script>
    
    
    <apex:form id="fm" > 
        <apex:outputPanel rendered="{!recordsTable}"  id="tabledata">            
            <apex:sectionHeader subtitle="Edit Schedule for test {!oli.Product2.Name}"/>
            <p>Modify the schedule for this product. Click Recalculate to preview how your changes affect the total amount of the product. The total amount is the sum of the schedule installments. This total amount will override the amount stored on the product.
            </p>
            <apex:pageBlock id="pbl">  
 
                <!--VF Table starts here-->
                <apex:pageBlockTable value="{!lstWrapObj}" var="objWrap" id="pblt">             
                    <apex:column headerValue="Date">                     
                        <!--apex:input type="date" value="{!objWrap.wrapDate}"/-->                  
                        <apex:inputField value="{!objWrap.wrapOps.Start_Date__c}"/>
                    </apex:column>                  
                    <apex:column headerValue="Quantity" rendered="{!inputQuantityHide}" id="qc">   
                        <apex:inputText value="{!objWrap.Quantity}" rendered="{!inputQuantityHide}" id="qq" /> 
                        
                    </apex:column>  
                    
                    <apex:column headerValue="Revenue" rendered="{!inputRevenueHide}"> 
                        <apex:inputText value="{!objWrap.Revenue}" rendered="{!inputRevenueHide}"/>  
                    </apex:column>                
                    <apex:column headerValue="Comments">
                        <apex:inputText value="{!objWrap.Comments}" />                     
                    </apex:column>    
                    
                    <apex:column headerValue="Amount">
                        <apex:inputText value="{!objWrap.amount}" />                     
                    </apex:column>
                    
                </apex:pageBlockTable>  
                <!--VF Table ends here-->    
                
                <apex:pageBlockButtons >
                    <!--apex:commandButton value="Add Row" action="{!addRows}" reRender="all,tabledata,fm"/-->
                    <apex:commandButton value="Save" action="{!commitToDatabase}" /> 
                    <apex:commandButton value="Save & More" action="{!saveAndMore}" reRender="all,tabledata,fm" onclick="validation();" /> 
                    <apex:commandButton value="Cancel" action="{!tableCancel}" /> 
                </apex:pageBlockButtons>
            </apex:pageBlock>  
        </apex:outputPanel>
    </apex:form>
</apex:page>
Hi, 

I have the below code but I just keep getting a syntax error, I want to display 1 flow if the users country is united kingdom and if not it defaults to a different flow, Here is my code below: 

<apex:page standardController="Vacation_Request__c">

    <apex:sectionheader title="Holiday Request - {!$User.FirstName} {!$User.LastName}"></apex:sectionheader>

    {!IF(({!$User.Country} == 'United Kingdom'),
    

    <flow:interview name="Vacation_Request" finishLocation="{!URLFOR('/home/home.jsp')}">
        <apex:param name="var_UserId" value="{!$User.Id}"></apex:param>
        <apex:param name="var_Username" value="{!$User.FirstName} {!$User.LastName}"></apex:param>
    </flow:interview>,
    
     <flow:interview name="Canada_Vaction_Request" finishLocation="{!URLFOR('/home/home.jsp')}">
        <apex:param name="var_UserId" value="{!$User.Id}"></apex:param>
        <apex:param name="var_Username" value="{!$User.FirstName} {!$User.LastName}"></apex:param>
    </flow:interview>
     
     )}
     
</apex:page>


any help would be much appericated. 

Thanks 
Hi All,

I am using this code .
Map<String, Object> results = (Map<String, Object>) JSON.deserializeUntyped(res.getBody());
                    System.debug('results::'+results);
                    System.debug('results.get()::'+results.get('items'));


 I want to get the "customer_id" in apex
{items=({addresses=({city=ewing, country_id=US, customer_id=18,  firstname=nini, id=19, lastname=nini, postcode=08628, region={region=New Jersey, region_code=NJ, region_id=41}, ...}),
 , custom_attributes=({attribute_code=phone_number, value=1231231234}, {attribute_code=account_number, value=147439}), default_billing=19,  email=ninin@example.com, firstname=nini, group_id=0, ...}), 
search_criteria={filter_groups=({filters=({condition_type=eq, field=email, value=ninin@example.com})})}, 
total_count=1}

When I using   System.debug('results.get()::'+results.get('items'));  . I am getting the below value 

({addresses=({city=ewing, country_id=US, customer_id=18, default_billing=true, default_shipping=true, firstname=nini, id=19, lastname=nini, postcode=08628, region={region=New Jersey, region_code=NJ, region_id=41}, ...}), created_at=2019-01-02 15:58:29, created_in=Default Store View, custom_attributes=({attribute_code=phone_number, value=1231231234}, {attribute_code=account_number, value=147439}), default_billing=19, default_shipping=19, disable_auto_group_change=0, email=ninin@example.com, firstname=nini, group_id=0, ...})

results.get('items').get("addresses") -- is not working

Please help me to get the "customer_id" value.
Thanks,