• Ajay Ghuge 6
  • NEWBIE
  • 232 Points
  • Member since 2015


  • Chatter
    Feed
  • 5
    Best Answers
  • 0
    Likes Received
  • 1
    Likes Given
  • 3
    Questions
  • 60
    Replies
Dears,

I want to realize a function similar with "vlookup" with Apex and I tried coding like following but not correct.

Background:
I have 2 standard object: opportunities and quotes (lookup relationship, opportunities is father). In opportunities I have a picklist field named "City".

And I create a customized filed called "Destination information". For each value in the picklist "city", I have a record in "Destination information", named with the same picklist value.

Now I created a lookup function between Quotes and  "Destination information". I want to get the ID of that City in "Destination information" to Quotes.

For example: In opportunity there is 1 record with the "City" field value "Paris", and the record named "Paris" in "Destination information" has a ID 0062800000P6Dg6. I want to get that ID and give it to the lookup field "Destination_information" in the Quote records related to that opportunity.

Here following my code (not correct)
trigger GetDestinationID on Quotes (before insert, before update) {
for (Quotes quotes : Trigger.new) {
    String desid = Quotes.Destination_information__c;
    List<Destination_information__c> Destination_information = [SELECT Id FROM Destination_information WHERE Quotes__r.Opportunity.City__c = :desid];
    if(Destination_information != null)
             Quotes.Destination_information__c = Destination_information[0].Id;
    }
}
Thanks in advance!
 
We have a custom field (number type) on Leads, Opportunities and Accounts. We would like the field to update on all three records regardless of which object the user updates it on. Is this possible? (I am not a programmer and have never used triggers before; can I get help with how to use them, if they are the answer?) Thanks.
Hi All,
I am trying to insert record based on the record type.but while trying the the logic is not going into the if condition.and is the write way to take hardcode id for inserting record ?please help me below is the code.

public with sharing class insertinrecordtypecontroller {

public String name { get; set; }
public String value { get; set; }

public PageReference Insertvalue() {
    position__C po=new position__c();
        system.debug('this is insert value 111111111');

    if(po.RecordTypeId =='01228000000Aif1AAC'){
    po.name=name;
    po.value__c=value;
    system.debug('this is insert value');
    insert po;
    }
    return null;
  }
}


visual force:
=----------------

<apex:page controller="insertinrecordtypecontroller">
<apex:form >
 <apex:pageBlock >
 <apex:pageBlockSection >
 <apex:inputText label="name" value="{!name}" />

<apex:inputText label="value" value="{!value}" />
</apex:pageBlockSection>

 </apex:pageBlock> 
 <apex:commandButton value="save" action="{!Insertvalue}"/>

 </apex:form>
</apex:page>


Thanks,
B.Mahanandeesh.
  • May 15, 2016
  • Like
  • 0
Documenting a meeting with a custom object (Created by Salesforce for us) is in need of adding multiple attendees.  Currently one one can be added. 
I see it is available in creating a meeting and would like to use in the custom object.

<apex:form >
        <apex:actionRegion >
            <apex:selectList value="{!objClass.Class_Meets__c}" multiselect="true">
                <apex:selectOptions value="{!items}"/>
            </apex:selectList>
            
            <apex:inputField value="{!objClass.Class_Meets__c}">
                <apex:actionSupport event="onchange" action="{!showPanel}" rerender="panel">
                    <apex:param value="{!objClass.Class_Meets__c}" name="classmeets" assignTo="{!classmeets}"/>
                </apex:actionSupport>
            </apex:inputField>    
        </apex:actionRegion>
        
         <apex:outputPanel id="panel">
         <apex:outputPanel rendered="{!flag}">
                   {!objClass.Class_Meets__c}
                   {!classmeets}
            </apex:outputPanel>
        </apex:outputPanel>
    </apex:form>

where "classmeets" is string. I am not able to get the currently selected picklist value in controller.  {!objClass.Class_Meets__c} displays the selected values but "classmeets" come null. 

Hello Everyone,

I am getting the below string format : 
string strTest = '_billing_tp_1_address_2: XYZ , _billing_tp_1_address_2: ABC,XYZ';

The code strTest.split(',') will produce 3 values : 
1) _billing_tp_1_address_2: XYZ
2)_billing_tp_1_address_2: ABC
3) XYZ

However, I want the following output: 
1) _billing_tp_1_address_2: XYZ
2)_billing_tp_1_address_2: ABC,XYZ 

I tried the different patterns of the split but they are giving the same output.

Let me know if anyone knows this split in the way I want.

Regards,
Ajay 




 
Getting the following issue while solving the Understand Cross-Site Scripting (XSS) trail under Understand Cross-Site Scripting (XSS) Module.

"There was an unhandled exception. Please reference ID: VNEMXUKK. Error: Faraday::ClientError. Message: INVALID_TYPE: select id from cvcs__c where name = 'xbc1' and ^ ERROR at Row:1:Column:16 sObject type 'cvcs__c' is not supported. If you are attempting to use a custom object, be sure to append the '__c' after the entity name. Please reference your WSDL or the describe call for the appropriate names."

The cvcs__c is a custom setting.
 
Hi Folks,

I need to get the attachments from EmailMessage. Is there any way to get it ? EmailMessage object has a property called hasattachments but how to get attachments and its body ?

Regards,
Ajay
Hi,

Can someone can tell how to parse the below XML in APEX using XmlStreamWriter?

<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
</s:Envelope>

Thanks!!
 
I have tried to create a Batch Class on the ContentDocumentLink. The querylocator in the start method is returning some records but it is not able to execute the execute() method. I am getting Internal Salesforce.com Error. May I know is there any limitations to this object?

Here is the code snippet I am using:
 
global class CommunityActivityJob implements Database.Batchable<sObject>,Database.AllowsCallouts ,Database.Stateful {
    global Database.QueryLocator start(Database.BatchableContext BC) {
    List<String> linked = new List<String>();
    linked.add('00528000000M2xj');
       String query = 'Select Id, ContentDocumentId, LinkedEntityId, ShareType, Visibility from ContentDocumentLink Where LinkedEntityId In :linked ';
        System.debug('===START==='+Database.query(query));
        return Database.getQueryLocator(query);
    }
     global void execute(Database.BatchableContext BC, List<sObject> scope) {
        System.Debug('===INSIDE EXECUTE==='+scope);
        }
    global void finish(Database.BatchableContext BC) {
        System.debug('===Inside Finish===');
    }

 
Hello
I'm processing flat structure object into two objects with relation, it's more complicated, but I want to show it simplified. I want to create mass of records with reference in a for loop. Issue is that Id of Account  is not populated in one transaction. To do this I would have to add insert in a loop (bad practice).

Account (one-to-many lookup relation) Marker__c sobject
public class MyProcessor implements Queueable{
	public void execute(QueueableContext context) {

		List<Stage_Object__c> counterparties = [SELECT Counterparty_Identifier__c, Full_Name__c, Processed__c
                                              	FROM Stage_Object__c
                            				   	WHERE Processed__c = false LIMIT 3300];
		List<Account> accList = new List<Account>();
		List<Marker__c> markerList = new List<Marker__c>();
		for (Stage_Object__c so : counterparties){
			Account na = new Account(Name = so.Full_Name__c);
			accList.add(na);
			Marker__c m = new Marker__c(Account_ref__c = na.Id,
										Identifier__c = so.Counterparty_Identifier__c);
			m.Account_ref__c = na.Id;
			markerList.add(m);
			so.Processed__c = true;
		}
		try {
			insert accList;
			insert markerList;
			update counterparties;
		} catch (DMLException de){
			//handling Exception
		}
	}
}

Relation is not created, as Account Id is not created in Force.com database. I want to omit many inserts in a loop. It's a process with many records so I don't want to meet the limits and write it efficient.

I tried even something like that:
Account na = new Account(Name = 'Salesforce');
Marker__c m = new Marker__c(Counterparty_Identifier__c = 'some test id',
                            Account_ref__r = na);
insert m;
ResultError: System.DmlException: Insert failed. First exception on row 0; first error: INVALID_FIELD, More than 1 field provided in an external foreign key reference in entity: Account: []
or
Marker__c m = new Marker__c(Identifier__c = 'some test id');
Account na = new Account(Name = 'Hollywood Inc.');
na.Marker_r = m;

insert na;
ResultError: Field is not writeable: Account.Marker_r

I tried also add them in one List<SObject> and insert in one transaction (two chunks), but reference also wasn't added.

Thanks for your ideas and thoughts,
DJ
Dears,

I want to realize a function similar with "vlookup" with Apex and I tried coding like following but not correct.

Background:
I have 2 standard object: opportunities and quotes (lookup relationship, opportunities is father). In opportunities I have a picklist field named "City".

And I create a customized filed called "Destination information". For each value in the picklist "city", I have a record in "Destination information", named with the same picklist value.

Now I created a lookup function between Quotes and  "Destination information". I want to get the ID of that City in "Destination information" to Quotes.

For example: In opportunity there is 1 record with the "City" field value "Paris", and the record named "Paris" in "Destination information" has a ID 0062800000P6Dg6. I want to get that ID and give it to the lookup field "Destination_information" in the Quote records related to that opportunity.

Here following my code (not correct)
trigger GetDestinationID on Quotes (before insert, before update) {
for (Quotes quotes : Trigger.new) {
    String desid = Quotes.Destination_information__c;
    List<Destination_information__c> Destination_information = [SELECT Id FROM Destination_information WHERE Quotes__r.Opportunity.City__c = :desid];
    if(Destination_information != null)
             Quotes.Destination_information__c = Destination_information[0].Id;
    }
}
Thanks in advance!
 
I need to implement Custom checkbox field called private on opportunity. On checking this field, all users should be prevented from accessing the opportunity record except the Opportunity Team members. How to remove users for this oppty from opportunityshare object using trigger or apex??
Please help me !!
  • September 20, 2017
  • Like
  • 0
How can i validate mobile number should be 10 digit in trigger.I have created a trigger but its not working
trigger MobileNumber on Account (before update,before insert) {
 if( Trigger.isbefore && Trigger.isInsert)
    {
    for(Account l: Trigger.New){
        if(l.Mobile__c!=null && Mobile__c.lenght()=10){
alert ("Error");
        
    
      
        }
    }
}



}

 
We have a custom field (number type) on Leads, Opportunities and Accounts. We would like the field to update on all three records regardless of which object the user updates it on. Is this possible? (I am not a programmer and have never used triggers before; can I get help with how to use them, if they are the answer?) Thanks.
Been working on this one for a while.  Trying to cycle through the AsyncApex and send a list of errors as a csv to an email address:  I don't believe I am attaching the file correctly (or even creating it correctly).  My code is as follows:

global class AriaBatchErrors implements Database.Batchable<sOBject>, Database.Stateful{
   
    global string excelHeader = 'ApexClassId, CompletedDate , ExtendedStatus, JobItemsProcessed, JobType, MethodName, NumberOfErrors, Status, TotalJobItems \n';
    global string finalstr = '';
   
    //constructor
    global AriaBatchErrors(){
        finalstr = excelHeader;
    }
    //start method
    global Database.QueryLocator start(Database.BatchableContext BC){
        return Database.getQueryLocator('SELECT ApexClassId, CompletedDate, ExtendedStatus, JobItemsProcessed, JobType, MethodName, NumberOfErrors, Status, TotalJobItems FROM AsyncApexJob WHERE NumberOfErrors > 0');
    }
 
    //execute
    global void execute(Database.BatchableContext BC, List<sOBject> scope){
        string recordString;
        for(sOBject a: scope){
            // Type Cast sOBject to AsyncApexJob
            AsyncApexJob asyncApexJobRecord = (AsyncApexJob) a;
           
            recordString = asyncApexJobRecord.ApexClassID +',' + asyncApexJobRecord.CompletedDate +','+ asyncApexJobRecord.ExtendedStatus+',' + asyncApexJobRecord.JobItemsProcessed + ',' + asyncApexJobRecord.JobType +  ',' + asyncApexJobRecord.MethodName + ',' + asyncApexJobRecord.NumberOfErrors + ',' + asyncApexJobRecord.TotalJobItems + ','+ asyncApexJobRecord.CreatedBy.Email + '\n';
            finalstr =+ finalstr + recordString;
         //   asyncApexJobRecord.JobItemsProcessed + ',' +asyncApexJobRecord.JobType + ',' + asyncApexJobRecord.TotalJobItems+','+ asyncApexJobRecord.CreatedBy.Email + '\n';
        }
    }
    
    //finish
    global void finish (Database.BatchableContext BC){
       
        system.debug('**** Final String *** ' + finalstr);
        //TODO: pass this string to create CSV in your CSV Method.
            String csvContent = finalstr;
                Attachment attachment = new Attachment();
                attachment.Body = Blob.valueOf(csvContent);
                attachment.Name = 'csvFile.csv';
              
                insert attachment;
       
            //TODO: Create an generic method to send emails & pass this attachment.
            
        Messaging.Singleemailmessage mail = new Messaging.Singleemailmessage();
            mail.setToAddresses((new String[] {'test@test.com'}));
            //mail.setReplyTo('noreply@privatebudget.com');
            mail.setSenderDisplayName('Batch Class Errors');
            mail.setSubject('Batch Class Errors');
            mail.setBccSender(false);
            mail.setUseSignature(false);
            mail.setPlainTextBody('This is a test');
            system.debug('@@@@ sendEmail - mail : ' + mail);
            Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
 
    }
}
 

I do receive an email a few minutes later, here are the contents.

Sandbox: Developer script exception from EchoSign, Inc. : 'AriaBatchErrors' for job id '7071800000gP8l4' : Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [ParentId]: [ParentId]


Sandbox

Apex script unhandled exception by user/organization: 00518000001WfNj/00D180000008oBS
Source organization: 00D300000006IaD (null)
Failed to process batch for class 'AriaBatchErrors' for job id '7071800000gP8l4'

caused by: System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [ParentId]: [ParentId]

Class.AriaBatchErrors.finish: line 39, column 1

Debug Log:
40.0 APEX_CODE,DEBUG;APEX_PROFILING,FINEST;CALLOUT,FINEST;DB,FINEST;SYSTEM,FINE;VALIDATION,INFO;VISUALFORCE,FINER;WAVE,FINEST;WORKFLOW,FINER
15:54:08.0 (257958)|USER_INFO|[EXTERNAL]|00518000001WfNj|all60388@adobe.com.signstage|Pacific Standard Time|GMT-07:00
15:54:08.0 (287766)|EXECUTION_STARTED
15:54:08.0 (290789)|CODE_UNIT_STARTED|[EXTERNAL]|01p1800000062WP|AriaBatchErrors
15:54:08.0 (12257171)|SYSTEM_METHOD_ENTRY|[32]|System.debug(ANY)
15:54:08.0 (12286463)|USER_DEBUG|[32]|DEBUG|**** Final String *** ApexClassId, CompletedDate , ExtendedStatus, JobItemsProcessed, JobType, MethodName, NumberOfErrors, Status, TotalJobItems 

15:54:08.0 (12295041)|SYSTEM_METHOD_EXIT|[32]|System.debug(ANY)
15:54:08.0 (12482382)|SYSTEM_METHOD_ENTRY|[36]|Blob.valueOf(String)
15:54:08.0 (12528807)|SYSTEM_METHOD_EXIT|[36]|Blob.valueOf(String)
15:54:08.0 (12699903)|DML_BEGIN|[39]|Op:Insert|Type:Attachment|Rows:1
15:54:08.0 (12712483)|LIMIT_USAGE|[39]|DML|1|150
15:54:08.0 (12722414)|LIMIT_USAGE|[39]|DML_ROWS|1|10000
15:54:08.0 (83455960)|CODE_UNIT_STARTED|[EXTERNAL]|01q40000000Td0s|AttachmentTrigger on Attachment trigger event BeforeInsert for [new]
15:54:08.0 (83670879)|SYSTEM_METHOD_ENTRY|[13]|Limit.getLimitQueries()
15:54:08.0 (83707497)|SYSTEM_METHOD_EXIT|[13]|Limit.getLimitQueries()
15:54:08.0 (83717576)|SYSTEM_METHOD_ENTRY|[13]|Limit.getQueries()
15:54:08.0 (83724294)|SYSTEM_METHOD_EXIT|[13]|Limit.getQueries()
15:54:08.0 (83730393)|SYSTEM_METHOD_ENTRY|[13]|Limit.getLimitDmlRows()
15:54:08.0 (83735294)|SYSTEM_METHOD_EXIT|[13]|Limit.getLimitDmlRows()
15:54:08.0 (83740959)|SYSTEM_METHOD_ENTRY|[13]|Limit.getDmlRows()
15:54:08.0 (83746131)|SYSTEM_METHOD_EXIT|[13]|Limit.getDmlRows()
15:54:08.88 (88592579)|CUMULATIVE_LIMIT_USAGE
15:54:08.88 (88592579)|LIMIT_USAGE_FOR_NS|(default)|
  Number of SOQL queries: 0 out of 200
  Number of query rows: 0 out of 50000
  Number of SOSL queries: 0 out of 20
  Number of DML statements: 1 out of 150
  Number of DML rows: 1 out of 10000
  Maximum CPU time: 0 out of 60000
  Maximum heap size: 0 out of 12000000
  Number of callouts: 0 out of 0
  Number of Email Invocations: 0 out of 10
  Number of future calls: 0 out of 0
  Number of queueable jobs added to the queue: 0 out of 1
  Number of Mobile Apex push calls: 0 out of 10

15:54:08.88 (88592579)|TOTAL_EMAIL_RECIPIENTS_QUEUED|0
15:54:08.88 (88592579)|STATIC_VARIABLE_LIST|
  char[]:DigitTens:0
  long:serialVersionUID:0
  long:serialVersionUID:0
  String:_sfdcAdditionalCodeLocations:0
  double:MAX_VALUE:0
  Boolean:FALSE:0
  long:serialVersionUID:0
  double:MIN_VALUE:0
  int:SIZE:0
  double:NEGATIVE_INFINITY:0
  int:MAX_VALUE:0
  String:_sfdcAdditionalCodeLocations:0
  char[]:digits:0
  double:NaN:0
  Boolean:TRUE:0
  String:_sfdcAdditionalCodeLocations:0
  String:_sfdcSuppressedCodeLocations:0
  int:MIN_VALUE:0
  char[]:DigitOnes:0
  int:BYTES:0
  int:MIN_EXPONENT:0
  int[]:sizeTable:0
  int:MAX_EXPONENT:0
  String:_sfdcAdditionalCodeLocations:0
  String:__sfdcParameterizedTypes:0
  int:SIZE:0
  double:POSITIVE_INFINITY:0
  double:MIN_NORMAL:0
  int:BYTES:0

15:54:08.88 (88592579)|CUMULATIVE_LIMIT_USAGE_END

15:54:08.0 (89922641)|CODE_UNIT_FINISHED|AttachmentTrigger on Attachment trigger event BeforeInsert for [new]
15:54:08.0 (93268983)|DML_END|[39]
15:54:08.0 (93369881)|EXCEPTION_THROWN|[39]|System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [ParentId]: [ParentId]
15:54:08.0 (93774368)|FATAL_ERROR|System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [ParentId]: [ParentId]

Class.AriaBatchErrors.finish: line 39, column 1
15:54:08.113 (113740269)|CUMULATIVE_PROFILING_BEGIN
15:54:08.113 (113740269)|CUMULATIVE_PROFILING|No profiling information for SOQL operations
15:54:08.113 (113740269)|CUMULATIVE_PROFILING|No profiling information for SOSL operations
15:54:08.113 (113740269)|CUMULATIVE_PROFILING|DML operations|
Class.AriaBatchErrors.finish: line 39, column 1: Insert: Attachment: executed 1 time in 81 ms

15:54:08.113 (113740269)|CUMULATIVE_PROFILING|method invocations|
External entry point: global void finish(Database.BatchableContext): executed 1 time in 82 ms
External entry point: public void invoke(): executed 1 time in 5 ms
Class.AttachmentTriggerHandler.executeOperations: line 19, column 1: private static void onBeforeInsert(List<Attachment>): executed 1 time in 0 ms
Trigger.AttachmentTrigger: line 13, column 1: global public static Integer getLimitQueries(): executed 4 times in 0 ms
Trigger.AttachmentTrigger: line 14, column 1: public static void executeOperations(List<Attachment>, List<Attachment>, Map<Id,Attachment>, Map<Id,Attachment>, Boolean, Boolean, Boolean, Boolean, Boolean, Boolean, Boolean): executed 1 time in 0 ms
Class.AriaBatchErrors.finish: line 32, column 1: global public static void debug(ANY): executed 1 time in 0 ms
Class.AriaBatchErrors.finish: line 36, column 1: public static Blob valueOf(String): executed 1 time in 0 ms

15:54:08.113 (113740269)|CUMULATIVE_PROFILING_END



(I am just lost, thank you for any help/guidance)

 
I am new to Salesforce.com.  I am following the example in the Force.com IDE manual and created the trigger and class, however, when I add an Account, the Description field is not populated with "Hello World".  So it seems my trigger and class are not getting activated.

Also, when I went to save in Eclipse, I got a message that it was not in sync with the organization, but I continued anyway.  My class and trigger are saved on the site though so it seems things are ok.
Hi everyone,

I was wondering if it was possible to load a standard page for one user profile (i.e. content manager) but if the user profile is different (i.e. account manager) load a custom VF page? How would I go abouts to achieve this?

Thanks
Hello Everyone,

I am getting the below string format : 
string strTest = '_billing_tp_1_address_2: XYZ , _billing_tp_1_address_2: ABC,XYZ';

The code strTest.split(',') will produce 3 values : 
1) _billing_tp_1_address_2: XYZ
2)_billing_tp_1_address_2: ABC
3) XYZ

However, I want the following output: 
1) _billing_tp_1_address_2: XYZ
2)_billing_tp_1_address_2: ABC,XYZ 

I tried the different patterns of the split but they are giving the same output.

Let me know if anyone knows this split in the way I want.

Regards,
Ajay 




 
Hi Folks,

I need to get the attachments from EmailMessage. Is there any way to get it ? EmailMessage object has a property called hasattachments but how to get attachments and its body ?

Regards,
Ajay

When someone takes the time/effort to repspond to your question, you should take the time/effort to either mark the question as "Solved", or post a Follow-Up with addtional information.  

 

That way people with a similar question can find the Solution without having to re-post the same question again and again. And the people who reply to your post know that the issue has been resolved and they can stop working on it.