• Siju
  • NEWBIE
  • 170 Points
  • Member since 2010


  • Chatter
    Feed
  • 4
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 25
    Replies
Hi,

We have a custom metadata type (CustomMetadata__mdt). When a record of CustomMetatdata__mdt is inserted we want to call a trigger that will append extra characters to the end of the field's values. 

How would we create a trigger that will run whenever a new record is inserted for CustomMetadata__mdt?
  • January 17, 2017
  • Like
  • 0
I'm trying to count the number of accounts a user owns as well as stamping the last login date in a custom field within the same class but I'm receiving the error below on my scheduled class.

Invalid integer: common.apex.runtime.impl.SObjectList@c21a4303

My class...

global class LoginDateClass implements Schedulable{

    global void execute(SchedulableContext SC){
    
    list<user> userList = [SELECT Id,Total_Number_of_Accounts__c,LastLoginDate FROM User WHERE IsActive = TRUE LIMIT 9999];
    LIST<AggregateResult> NoOfAccounts = [SELECT OwnerId u, count(Id) a FROM Account WHERE CoreAccounts__Inactive__c = FALSE  AND OwnerId in :userList GROUP BY OwnerId];
    
    
    for(User user : userList){
        user.Last_Login__c = user.LastLoginDate;
        user.Total_Number_of_Accounts__c  = integer.valueOf(NoOfAccounts);
        }
        update userList;   
      }
}

Hi,

I have 3 objects

1. Case
2. Risk Profile
3. Investment option.

Case and Investment option has a look up field to Risk Profile.

I am trying to write a query to include details from the case, related risk profile and all the child investment options to the given risk profile.

So far I am able get the information in 2 separate queries, haven't found much luck in combining them togather.

Query 1. Select name, (SELECT name FROM investment_options__r) From Risk_Profile__c
Query 2. Select name, (SELECT name FROM Cases) From Risk_Profile__c

Any Help is appreciated.

Thanks

Talal

 

With good reason, How do I show white space (blank) instead of --none-- in a visualforce case picklist? 

​I have about 10 picklist fields. None are required and I want the ones that have no value to be blank white space instead of "--none--". 

The reason for this is to keep my UI looking clean and readable.
Having 10 fields with a label and "--none--" beside each of them is very cumbersome. I'd much rather they just show blank.
How to pass an an attribute to XML message in SOAP webservice callout .
Example I want to pass  mac:bar

**WSDL - Imported in SOAP UI**
<foo mac:bar="TestAttribute">Test data</foo>



**APEX Generated from WSDL**
public String bar;
private String[] bar_att_info = new String[]{'bar'};


**APEX Stub**
 dtRT.bar='TestBarData';


The request that I am passing from Apex is not having the mac:bar="TestAttribute" . SOAP UI everything is working fine . Any pointers are helpful .thanks

 
  • June 25, 2021
  • Like
  • 0
I am trying to send an Image and some details to external system (REST JSON). I added the image like this mapEmp.put('image',att.body);   It is not working and throwing error  but  If I remove that line ,its working fine with out image.Please  check it let meknow I am missing anything or approch is wrong?

 HttpRequest req = new HttpRequest();
        Attachment att = new Attachment();
       att = [SELECT ID,Body,ContentType FROM Attachment where ContentType='image/jpeg' and ID='00PD000008GcfohMAB' LIMIT 1];
        req.setEndpoint('http://abc');
        req.setMethod('POST');
        String username = 'abc@xxx.org';
        String password = 'password1';
        Blob headerValue = Blob.valueOf(username + ':' + password);
        String authorizationHeader = 'Basic ' + EncodingUtil.base64Encode(headerValue);
        req.setHeader('Authorization', authorizationHeader);      
        req.setHeader('Content-Type', 'multipart/form-data');
        req.setHeader('Content-Type', 'application/json');     
        system.debug('Auth Header: ' + authorizationHeader);
        Map<String,object> mapEmp = new Map<String,object>();
        mapEmp.put('title', title);
        mapEmp.put('authorDisplayName', authorDisplayName);
        mapEmp.put('lastUpdatedDate',publishedDate);
        mapEmp.put('itemId',itemId);
        mapEmp.put('image',att.body);        
        String JSONString = JSON.serialize(mapEmp);       
        req.setBody(JSONString);         
        Http http = new Http();
        HTTPResponse res = http.send(req);
        System.debug('Body ' + res.getBody());
        system.debug('----res'+res);
        if(res.getStatusCode() == 200)
        { 
            system.debug('Authentication success!!!' + res);           
             
        }
        else
        {
            system.debug('Authentication failed!!!' + res + res.getStatusCode());
          
        } 
        return null;
    }
  • April 30, 2015
  • Like
  • 0
Hello there,

I am having a hard time trying to get lightning:select component selected value in controller :

Here is my code :
component :
<aura:component implements="flexipage:availableForRecordHome,force:hasRecordId" access="global" >
    
        <!-- handlers-->
        <aura:handler name="init" value="{!this}" action="{!c.init}"/>
    
            <lightning:select name="distance" label="Distance ?" onchange="{!c.onChange}">
                <option value="10km">10</option>
                <option value="25km">25</option>
                <option value="50km">50</option>
                <option value="100km">100</option>
            </lightning:select>
           
</aura:component>
controller:
({
     
init: function (component, event, helper) {
    
    	console.log('distance ' + component.find("distance").get("v.value"));

    },
    
    onChange: function (component, event, helper) {
    	console.log(component.find("distance").get("v.value"));
    }
})
wheh the page loads or when I change the picklist value, I get his error message :
 
Action failed: c:map$controller$init [component.find(...) is undefined]

Thanks a lot for your help !

 
How do we find if a given field is part of a Master-detail or a lookup relationship? Using SOAP API, the describesObjectResult
 has childobjects that does not have the relationship type.

 
==============
Parent
- opportunity
Child - Policy
============
i have a requirement where i need to have a auto number generated for child record(policy) , but child records for 1 parent(opportunity) should be like Pol - 1000 - v0
      Pol - 1000 - v1
2nd opportunity child record format :
Pol - 1001 - v0
Pol - 1001 - v2
3rd opportunity child record format :
Pol - 1002 - v0
Pol - 1002 - v1

i.e if parent record is same then child record will have same number with different version, increment in number will be based on (set of policy records) realted to parent records , so policy records having same parent will have same number.
  • February 07, 2017
  • Like
  • 0
Hi,

We have a custom metadata type (CustomMetadata__mdt). When a record of CustomMetatdata__mdt is inserted we want to call a trigger that will append extra characters to the end of the field's values. 

How would we create a trigger that will run whenever a new record is inserted for CustomMetadata__mdt?
  • January 17, 2017
  • Like
  • 0
I'm trying to count the number of accounts a user owns as well as stamping the last login date in a custom field within the same class but I'm receiving the error below on my scheduled class.

Invalid integer: common.apex.runtime.impl.SObjectList@c21a4303

My class...

global class LoginDateClass implements Schedulable{

    global void execute(SchedulableContext SC){
    
    list<user> userList = [SELECT Id,Total_Number_of_Accounts__c,LastLoginDate FROM User WHERE IsActive = TRUE LIMIT 9999];
    LIST<AggregateResult> NoOfAccounts = [SELECT OwnerId u, count(Id) a FROM Account WHERE CoreAccounts__Inactive__c = FALSE  AND OwnerId in :userList GROUP BY OwnerId];
    
    
    for(User user : userList){
        user.Last_Login__c = user.LastLoginDate;
        user.Total_Number_of_Accounts__c  = integer.valueOf(NoOfAccounts);
        }
        update userList;   
      }
}
Hi,
Could i have some help please here.
I need some fields to be updated each time sales people select specific products.
See screenshot below. If they put "Number of users" 2 and above, the "Do Not Apply Discounts needs to be ticked and the Additional Discounts(%) must go to 10%
Note:The field update should fire for 4 specific products only.
Do i have to create a workflow to the specific opportunity products?
Please help me with solving this error.
My trigger fires each time is record is inserted.It works fine with small data.Every night i get lot of inserts I am getting this error:: System.DmlException: Insert failed. first error: INVALID_FIELD_FOR_INSERT_UPDATE, cannot specify Id in an insert call: [Id]

below is my code
 
trigger Linktorecord on project__c (before insert,before update,after insert) {

    Map<String,product2> pMap=new Map<String,product2>();
    List<product2> p2List=new List<Product2>();
    List<Opportunity> oppList=New List<Opportunity>();
    List<Opportunity> oppList2=New List<Opportunity>();    
    oppList=[select id,name,accountid,serialnumber__c from opportunity where SerialNumber__c !=null];

    for(product2 pro  : [select id,productcode from product2]){
        pMap.put(pro.productcode,pro);
    }
   
  if(trigger.isinsert&&trigger.isbefore)
    for(Project__c I:trigger.new){

        if(i.Number__c != null && Pmap.Containskey(i.Number__c))
        {
            i.product__c=pMap.get(i.Number__c ).Id;
            break;
        } 
            
        else{
               
        Product2 newp =new Product2();
        if(i.number__c  !=null){        
        newp.Name=i.Number__c;
        }
        if(i.Number__c !=null){
        newp.ProductCode=i.Number__c;
        }
        p2List.add(newp);
        }
       
        insert p2List;
        if(p2List.size() >0){
        i.product__c=p2List[0].id; 
        }
       }
       
       if(trigger.isinsert && trigger.isafter){
       List<project__c> newproj =new List<project__c>();
       set<id> opids=new set<id>();
       newproj=trigger.new;
       Opplist2=[select id,SerialNumber__c,project__c from opportunity where Serialnumber__c =:newproj[0].Serialnumber__c];
       for(project__c I2:newproj){
         opids.add(i2.id);
       }
      if(!opids.isempty()){
      List<opportunity> oList =[select id,project__c from opportunity where Serialnumber__c =:newproj[0].Serialnumber__c];
       for(Opportunity ol:olist){
             
             ol.project__c =trigger.new[0].id;
       }      
      update olist;
      }       
    }
}

 
Hi
I am new to javascript and java.
Please tell me how to create a class in javascript?
Also it would be help if simple to advanced scenario interview questions can be sent on javascript and java.

Thanks
Vandana

 

Hi,

I have 3 objects

1. Case
2. Risk Profile
3. Investment option.

Case and Investment option has a look up field to Risk Profile.

I am trying to write a query to include details from the case, related risk profile and all the child investment options to the given risk profile.

So far I am able get the information in 2 separate queries, haven't found much luck in combining them togather.

Query 1. Select name, (SELECT name FROM investment_options__r) From Risk_Profile__c
Query 2. Select name, (SELECT name FROM Cases) From Risk_Profile__c

Any Help is appreciated.

Thanks

Talal

 

With good reason, How do I show white space (blank) instead of --none-- in a visualforce case picklist? 

​I have about 10 picklist fields. None are required and I want the ones that have no value to be blank white space instead of "--none--". 

The reason for this is to keep my UI looking clean and readable.
Having 10 fields with a label and "--none--" beside each of them is very cumbersome. I'd much rather they just show blank.
I have one object and 100 users one trigger will be fire. 50 users trigger will be fire and 50 users trigger will not be fire how to achive it ( Through Programing )
I am executing following soql query on SOAP API "SELECT NamespacePrefix FROM PackageLicense WHERE NamespacePrefix = 'scyc' LIMIT 1". But it returns "sObject type 'PackageLicense' is not supported." as error message. It was working just fine few days before. I don't understand what has changed? I have tried API v22 to API v39 but nothing worked. Please advise.
<apex:pageBlockSectionItem> may have no more than 2 child components
this error is seen what to do?
Hello,

I have a button like below,
<apex:inputText value="{!search}" id="search" />
controller{

public String search{get;set;}

funtion(){

}
}
I want to have a another button , which will clear the input text on front end and also in the back end

thank you for suggestions !!



 
  • November 05, 2015
  • Like
  • 0
I have a custom object and I have overridden "New" button for this object.
 On click of "New" I am showing a visualforce page with standard controller and extension.

There is a "Submit" button on this VF page and on cliclk of this button, Visualforce page calls a action method in the controller extension, which inserts a new record. After inserting this record I want to redirect use to the detail page of this record.

I am returning PageReference from my action method. But I see that redirect never happens and UI shows blank.

below the code snippet of my action method

public PageReference ValidateAndSave()
{
    
      insert refundGroup; //insert the record here

      system.debug('refund group id - ' + refundGroup.Id);
      //redirect to the newly created RefundGroup record
      PageReference pageRef = new PageReference('/' + refundGroup.Id + '?nooverride=1');
      pageRef.setRedirect(true);
      return pageRef;                   
 }


Please note the use of nooverride=1 in the URL.
this successfully inserts a record but never redirects to the detail page of the inserted record.

Any idea what is going on here and why redirect is not working ?