• mrki
  • NEWBIE
  • 35 Points
  • Member since 2016
  • Technical Consultant
  • Cerion Solutions

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 6
    Replies
Hi all.

I am trying to build a class where I can pass a name of an object.
This class should search all fields of that object.
if one of the fields is of DataType Picklist, it should E-Mail me the Picklist values.

My problem is: I am gettin a de-refernence Null error, but I can't find the line where it is null?!
 
private void sendpicklistvalues(String theObject, String theField){
Schema.DescribeFieldResult F = Schema.getGlobalDescribe().get(theObject).getDescribe().fields.getMap().get(theField).getDescribe();    
List<Schema.PicklistEntry> P = F.getPicklistValues();
String generatedCSVFile = theField + '\n';
List<String> queryFields = new List<String>{'Label','value'};
String fileRow = '';
for(Schema.PicklistEntry e: P){
fileRow = '';
fileRow = fileRow + e.getLabel();
fileRow = fileRow +','+ e.getValue();
generatedCSVFile = generatedCSVFile + fileRow + '\n';
}
Messaging.EmailFileAttachment csvAttachment = new Messaging.EmailFileAttachment();
Blob csvBlob = blob.valueOf(generatedCSVFile);
String csvName = 'picklistvalues.csv';
csvAttachment.setFileName(csvName);
csvAttachment.setBody(csvBlob);
Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
String[] toAddresses = new String[]{'david.brachten@qiagen.com'};
String subject = 'picklist.csv';
email.setSubject(subject);
email.setToAddresses(toAddresses);
email.setPlainTextBody(theField + ' - picklist labels and values');
email.setFileAttachments(new Messaging.EmailFileAttachment[]{csvAttachment});
Messaging.SendEmailResult[] r = Messaging.sendEmail(new Messaging.SingleEmailMessage[]{email});
}

private void describepicklists(String ofObject){
Map<String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
Schema.SObjectType leadSchema = schemaMap.get(ofObject);
Map<String, Schema.SObjectField> fieldMap = leadSchema.getDescribe().fields.getMap();
for (String fieldName: fieldMap.keySet()) {
Schema.DisplayType fielddataType = fieldMap.get(fieldName).getDescribe().getType();
if(fielddataType != Schema.DisplayType.Picklist) {
String thefieldname = fieldMap.get(fieldName).getDescribe().getLabel();
sendpicklistvalues(ofObject, thefieldname);
}
}
}

describepicklists('Account');
schemaMap and fieldMap are assignt so they are not null...
VARIABLE_ASSIGNMENT|[29]|schemaMap|"{account=Account, account_historic.....
VARIABLE_ASSIGNMENT|[31]|fieldMap|"{abc_classification__c=ABC_Cl

Does anybody see my mistake by chance?
 
I need API documentation for my Sales Cloud Lightning CRM – Enterprise Edition. Using API, I need to be able to 1) Create contacts in my salesforce and 2) Edit contacts in my salesforce.
Hi,

I have created trigger with hardcoding.
i want that to work dynamically.
Because, Recordtype Ids are different in Production and sandbox.

Kindly help me where i have to make changes exactly.

Following is my trigger code.
=========================================================================

trigger APACLeadExactTargetEmails on xtma_Individual_Email_Result__c (after insert, after update)
{
    
     set<Id> LeadRts = new Set<Id>{'012200000005uXiAAI','0127E000000CgrLQAS','0127E000000CgqNQAS'};

//    Id rtID= [select Id,name from RecordType where name ='APAC - Open'OR name ='Global Abandoned Checkout' OR name = 'Global New Web Registrant' limit 1].Id;

    Set<String> setIDs = new Set<String>();

    for(xtma_Individual_Email_Result__c Emails : trigger.new){
        if(Emails.Lead__c!=null){
            setIDs.add(Emails.Lead__c);
        }
    }

    List<lead> listLead = [ Select Id FROM Lead where RecordTypeId in :LeadRts AND id in :setIDs ] ;
    Map<String,Lead> mapKeyWiseLead = new Map<String,Lead>();
        for(Lead obj :  listLead )
        {
            String key = obj.id;
            mapKeyWiseLead.put(key,obj);
        }
        
    List<Lead> listUpdatelead = new List<Lead>();
    Set<String> setLeadID = new Set<String>();
    
    String key;
    for(xtma_Individual_Email_Result__c Emails : trigger.new)
    {
        key='';
        if(Emails.Lead__c!=null){
            key=Emails.Lead__c;
            
            if( mapKeyWiseLead.containsKey(key) )
            {
                Lead checkLead = mapKeyWiseLead.get(Key) ;
                
               if(emails.name.contains('1st Newsletter - EDE')) 
                {
                    checkLead.X1st_Email_Date__c= Emails.Date_Time_Sent__c.Date();

                    if(Emails.Date_Time_Sent__c!=null && Emails.Opened__c==FALSE && Emails.Number_of_Total_Clicks__c==null){
                        checkLead.X1st_Email_Outcome__c = 'Sent';
                    }
                    if(Emails.Date_Time_Sent__c!=null && Emails.Opened__c==TRUE && Emails.Number_of_Total_Clicks__c==null){
                        checkLead.X1st_Email_Outcome__c = 'Opened';
                    }
                    if(Emails.Date_Time_Sent__c!=null && Emails.Opened__c==TRUE && Emails.Number_of_Total_Clicks__c>0){
                        checkLead.X1st_Email_Outcome__c = 'Clicked';
                        }
                       if(emails.name=='1st Newsletter - EDE'){checkLead.X1st_Email_Name__c = '1st Newsletter - EDE';
                    }
                        listUpdatelead.add(checkLead);
                        setLeadID.add(checkLead.id);
                }
                if(emails.name.contains('2nd Newsletter - EDE'))
                {
                    checkLead.X2nd_Email_Date__c= Emails.Date_Time_Sent__c.Date();

                    if(Emails.Date_Time_Sent__c!=null && Emails.Opened__c==FALSE && Emails.Number_of_Total_Clicks__c==null){
                        checkLead.X2nd_Email_Outcome__c = 'Sent';
                    }
                    if(Emails.Date_Time_Sent__c!=null && Emails.Opened__c==TRUE && Emails.Number_of_Total_Clicks__c==null){
                        checkLead.X2nd_Email_Outcome__c = 'Opened';
                    }
                    if(Emails.Date_Time_Sent__c!=null && Emails.Opened__c==TRUE && Emails.Number_of_Total_Clicks__c>0){
                        checkLead.X2nd_Email_Outcome__c = 'Clicked';
                        }
                       if(emails.name=='2nd Newsletter - EDE'){checkLead.X2nd_Email_Name__c = '2nd Newsletter - EDE';
                    }
                        listUpdatelead.add(checkLead);
                        setLeadID.add(checkLead.id);
                }
                if(emails.name.contains('3rd Newsletter - EDE')) 
                {
                    checkLead.X3rd_Email_Date__c= Emails.Date_Time_Sent__c.Date();

                    if(Emails.Date_Time_Sent__c!=null && Emails.Opened__c==FALSE && Emails.Number_of_Total_Clicks__c==null){
                        checkLead.X3rd_Email_Outcome__c = 'Sent';
                    }
                    if(Emails.Date_Time_Sent__c!=null && Emails.Opened__c==TRUE && Emails.Number_of_Total_Clicks__c==null){
                        checkLead.X3rd_Email_Outcome__c = 'Opened';
                    }
                    if(Emails.Date_Time_Sent__c!=null && Emails.Opened__c==TRUE && Emails.Number_of_Total_Clicks__c>0){
                        checkLead.X3rd_Email_Outcome__c = 'Clicked';
                        }
                       if(emails.name=='3rd Newsletter - EDE'){checkLead.X3rd_Email_Name__c = '3rd Newsletter - EDE';
                    }
                        listUpdatelead.add(checkLead);
                        setLeadID.add(checkLead.id);
                }
                
            }
        }
    }
        if( listUpdatelead.size() > 0 )
        {
                try
                    {
                        update listUpdatelead;            
                    }
                catch(DMLException e)
                {  
                    System.debug('The following exception has occurred: ' + e.getMessage());
                }
        }
}

Regards,
Pranav
Still can't get the code below to work ,  for some reason I don't have the reply button, only the Answer button and when I use that to respond it's marking my own responses as best answer even the question is not solved yet.
 
trigger LeastCompetitorPrice on Opportunity (before insert, before update) {
    Integer highestPricePosition;
    Decimal highestPrices;
    Decimal lowestPrice;
    for(Opportunity opp : Trigger.new){
        //Add all our prices in a list in order of competitor
        List<Decimal> competitorPrices = new List<Decimal>();
        competitorPrices.add(opp.Competitor_1_Price__c);
        competitorPrices.add(opp.Competitor_2_Price__c);
        competitorPrices.add(opp.Competitor_3_Price__c);
        
        //Add all our competitors in a list in order
        List<String> competitors = new List<String>();
        competitors.add(opp.Competitor_1__c);
        competitors.add(opp.Competitor_2__c);
        competitors.add(opp.Competitor_3__c);
        
        //Loop through all competitors to find the position of the highest price
                   
        for(integer i = 0; i<competitorPrices.size();i++){
           Decimal currentPrice = competitorPrices.get(i);
           if(highestPrices == null || currentPrice > highestPrices){
                  opp.HighestPrice__c = highestPrices;
			system.debug(highestPrices);
                     opp.HighestPrice__c = competitorPrices.get(highestPrices);
              if(lowestPrice == null || currentPrice > highestPrices)
                  highestPricePositions = i;
                             
           }
        }
         //Populate the leading highestPrice field with the highest price
         // matching the highest price position
        // opp.Leading_Competitor__c = competitors.get(highestPricePosition); 
        
        
        
    }}

 
trigger accountcontact on Account (after insert) {
        list<id> AccountId= new list<Id>();
        for(contact con:Trigger.new){
            accountId.add(con.AccountId);
        }
            map<Id, Account>AccountMap= New map<Id, Account>([Select id,name,myruchika__client_contact__c from Account where Id IN:accountId]);
            list<account> updateaccountlist= new list<Account>();
            for(contact con :trigger.new){
                if(Accountmap !=null&& accountmap.size()>0)  {
                    for(Account acc: Accountmap) {
                        acc.myruchika__client_contact__c=con.Id;
                        updateAccountlist.add(acc);
                        
                    }
                }
            }
           
        if(updateAccountList !=null && updateaccountlist.size()>0)
            update updateAccountlist;
}

error=loop varible must be account type???
Hi all.

I am trying to build a class where I can pass a name of an object.
This class should search all fields of that object.
if one of the fields is of DataType Picklist, it should E-Mail me the Picklist values.

My problem is: I am gettin a de-refernence Null error, but I can't find the line where it is null?!
 
private void sendpicklistvalues(String theObject, String theField){
Schema.DescribeFieldResult F = Schema.getGlobalDescribe().get(theObject).getDescribe().fields.getMap().get(theField).getDescribe();    
List<Schema.PicklistEntry> P = F.getPicklistValues();
String generatedCSVFile = theField + '\n';
List<String> queryFields = new List<String>{'Label','value'};
String fileRow = '';
for(Schema.PicklistEntry e: P){
fileRow = '';
fileRow = fileRow + e.getLabel();
fileRow = fileRow +','+ e.getValue();
generatedCSVFile = generatedCSVFile + fileRow + '\n';
}
Messaging.EmailFileAttachment csvAttachment = new Messaging.EmailFileAttachment();
Blob csvBlob = blob.valueOf(generatedCSVFile);
String csvName = 'picklistvalues.csv';
csvAttachment.setFileName(csvName);
csvAttachment.setBody(csvBlob);
Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
String[] toAddresses = new String[]{'david.brachten@qiagen.com'};
String subject = 'picklist.csv';
email.setSubject(subject);
email.setToAddresses(toAddresses);
email.setPlainTextBody(theField + ' - picklist labels and values');
email.setFileAttachments(new Messaging.EmailFileAttachment[]{csvAttachment});
Messaging.SendEmailResult[] r = Messaging.sendEmail(new Messaging.SingleEmailMessage[]{email});
}

private void describepicklists(String ofObject){
Map<String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
Schema.SObjectType leadSchema = schemaMap.get(ofObject);
Map<String, Schema.SObjectField> fieldMap = leadSchema.getDescribe().fields.getMap();
for (String fieldName: fieldMap.keySet()) {
Schema.DisplayType fielddataType = fieldMap.get(fieldName).getDescribe().getType();
if(fielddataType != Schema.DisplayType.Picklist) {
String thefieldname = fieldMap.get(fieldName).getDescribe().getLabel();
sendpicklistvalues(ofObject, thefieldname);
}
}
}

describepicklists('Account');
schemaMap and fieldMap are assignt so they are not null...
VARIABLE_ASSIGNMENT|[29]|schemaMap|"{account=Account, account_historic.....
VARIABLE_ASSIGNMENT|[31]|fieldMap|"{abc_classification__c=ABC_Cl

Does anybody see my mistake by chance?
 
Hi, 

We need to sum up a value from a field in a custom object, and we just need some help with this. Here are some details on this-
a) Custom object: Network_Product__c
b) Data type: lookup relationship with Opportunity
c) Field needing summing: Revenue__c
d) field data type: Number
e) Need to show this sum in opportunity

How can we do this without changing custom object's relationship to master-detail. Please help, we are stuck on this.

Thank you !