• Tabrez Alam
  • NEWBIE
  • 10 Points
  • Member since 2014
  • Salesforce Developer
  • Techila Solutions

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 4
    Replies
I'm taking the records that meet the criteria in the list & then I'm updating the field

List<Object1__c> lstOfObject = [ SELECT Id, Object__c, Rule_Evaluation_Criteria__c, Status__c, (SELECT Id, Object2__r.Name,                      Object2__r.Object__c, Object2__r.Field__c, Object2__r.Operator__c, Object2__r.Value__c FROM Object1_Object2_JO__r), (SELECT Id, Object3__r.Rule_Name__c, Object3__r.Object_Name__c, Object3__r.Field_to_Update__c, Object3__r.Value_to_Update__c FROM Object1_Object2_JO__r) FROM Object1__c WHERE Object__c = 'Contact' AND Rule_Evaluation_Criteria__c = 'Record is Created' AND Status__c = 'Active' ];

This is the query that I'm using to get the records using the junction objects I've created a code if else condition to match the criteria that is entered
Once the criteria is met a field will be update so this is the code I'm using to update the field

for(Object1_Object3_JO__c objObject1Object3JO : objObject1.objObject1Object3JO __r)
{
if(isInCriteria==True)
{
a.put(objObject1Object3JO.Object3__r.Field_to_Update__c,objObject1Object3JO.Object3__r.Value_to_Update__c);
}
}

objObject1Object3JO.Object3__r.Field_to_Update__c
This variable stores the name of the field to update

objObject1Object3JO.Object3__r.Value_to_Update__c
This variable stores the value to assign to that field

I need the assign the Field that is stored in (objObject1Object3JO.Object3__r.Field_to_Update__c) the value that i have save in (objObject1Object3JO.Object3__r.Value_to_Update__c)

Please help me in achieve this
Thanks in advance
In my first page I have used getDescribe() function to get all the object of the org & I’m passing that selected object to another page using map where I will get the list of related fields of that object. On another page I have 5 rows as we have in standard workflow for rule criteria
When I’m selecting the field, operator & entering the value & saving it, each row is getting saved as a single record, by appending these fields using formula field example. “accountnumber = 123456” (Formula field of text type).
I’ve created a master detail relationship between the 2 custom objects “Rule” & “Rule Criteria”. The records of the Rule criteria are appearing under the appropriate ‘Rule Name’ related list.
Now my requirement is I need to fetch the records under ‘Rule Name’ one by one & from the object “Rule Criteria” & append them in a single string separating them by AND , example

This is my page 
-----------------------

Object : Account (output label for getting the selected object from the previous page)
Rule Name : My Example Rule (Text Field to enter rule name)
Evaluation Criteria : Record Is Created (Dropdown List)

Field Name             Operator      Value
Account Number       Equals      123456
Email                      Contains      example
Select Field               None
Select Field               None
Select Field               None

Now the records in the object will look like
Record 1
--------------
Rule Name : My Example Rule
Field : accountnumber
Operator : =
Value = 123456
Formula String : accountnumber = 123456

Record 2
--------------
Rule Name : My Example Rule
Field : email
Operator : LIKE \’%{val}%\ (i.e contains)
Value = test
Formula String : email LIKE \’%{val}%\ example

So the query will look like “ String str = select accountnumber, email from account where Record1.formula_string AND Record2.formula _string; “
So how can I get the functionality of the operators selected &
How can I write the string
Please assist
I'm taking the records that meet the criteria in the list & then I'm updating the field

List<Object1__c> lstOfObject = [ SELECT Id, Object__c, Rule_Evaluation_Criteria__c, Status__c, (SELECT Id, Object2__r.Name,                      Object2__r.Object__c, Object2__r.Field__c, Object2__r.Operator__c, Object2__r.Value__c FROM Object1_Object2_JO__r), (SELECT Id, Object3__r.Rule_Name__c, Object3__r.Object_Name__c, Object3__r.Field_to_Update__c, Object3__r.Value_to_Update__c FROM Object1_Object2_JO__r) FROM Object1__c WHERE Object__c = 'Contact' AND Rule_Evaluation_Criteria__c = 'Record is Created' AND Status__c = 'Active' ];

This is the query that I'm using to get the records using the junction objects I've created a code if else condition to match the criteria that is entered
Once the criteria is met a field will be update so this is the code I'm using to update the field

for(Object1_Object3_JO__c objObject1Object3JO : objObject1.objObject1Object3JO __r)
{
if(isInCriteria==True)
{
a.put(objObject1Object3JO.Object3__r.Field_to_Update__c,objObject1Object3JO.Object3__r.Value_to_Update__c);
}
}

objObject1Object3JO.Object3__r.Field_to_Update__c
This variable stores the name of the field to update

objObject1Object3JO.Object3__r.Value_to_Update__c
This variable stores the value to assign to that field

I need the assign the Field that is stored in (objObject1Object3JO.Object3__r.Field_to_Update__c) the value that i have save in (objObject1Object3JO.Object3__r.Value_to_Update__c)

Please help me in achieve this
Thanks in advance
In my first page I have used getDescribe() function to get all the object of the org & I’m passing that selected object to another page using map where I will get the list of related fields of that object. On another page I have 5 rows as we have in standard workflow for rule criteria
When I’m selecting the field, operator & entering the value & saving it, each row is getting saved as a single record, by appending these fields using formula field example. “accountnumber = 123456” (Formula field of text type).
I’ve created a master detail relationship between the 2 custom objects “Rule” & “Rule Criteria”. The records of the Rule criteria are appearing under the appropriate ‘Rule Name’ related list.
Now my requirement is I need to fetch the records under ‘Rule Name’ one by one & from the object “Rule Criteria” & append them in a single string separating them by AND , example

This is my page 
-----------------------

Object : Account (output label for getting the selected object from the previous page)
Rule Name : My Example Rule (Text Field to enter rule name)
Evaluation Criteria : Record Is Created (Dropdown List)

Field Name             Operator      Value
Account Number       Equals      123456
Email                      Contains      example
Select Field               None
Select Field               None
Select Field               None

Now the records in the object will look like
Record 1
--------------
Rule Name : My Example Rule
Field : accountnumber
Operator : =
Value = 123456
Formula String : accountnumber = 123456

Record 2
--------------
Rule Name : My Example Rule
Field : email
Operator : LIKE \’%{val}%\ (i.e contains)
Value = test
Formula String : email LIKE \’%{val}%\ example

So the query will look like “ String str = select accountnumber, email from account where Record1.formula_string AND Record2.formula _string; “
So how can I get the functionality of the operators selected &
How can I write the string
Please assist

I have a trigger on Opportunity that updates a text field on the Opportunity called WhatChanged__c. It's comparing the values on two related Opportunities and seeing if they are different. I need to reference the Field Label in the WhatChanged__c value, and I want to make it dynamic so that if we change any field labels/api names in the future the code will automatically handle the change.

 

Here is the relevant part of trigger:

 

//continue if there are cloned Opps moving into the pending stage
    if(!pendingClonedOpps.isEmpty()){
//get all the labels for Opportunity fields and put them in a map, keyed to the field api name String objectType ='Opportunity'; Map<String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe(); Schema.SObjectType leadSchema = schemaMap.get(objectType); Map<String, Schema.SObjectField> fieldMap = leadSchema.getDescribe().fields.getMap(); Map<String, String> fieldAPIName = new Map<String, String>(); for(String fieldName : fieldMap.keySet()){ fieldAPIName.put(fieldName, fieldMap.get(fieldName).getDescribe().getLabel()); } for(Opportunity opp : pendingClonedOpps){ //List to store all of the names of fields that have changed List<String> Changes = new List<String>(); //get the related Cloned Opportunity record Opportunity clonedFromOpp = ClonedOppIDToClonedOpp.get(opp.ClonedFrom__c); if(opp.Buyer__c != clonedFromOpp.Buyer__c){ String fieldName = 'buyer__c'; String Label = fieldAPIName.get(fieldName); String oldBuyer = clonedFromOpp.Buyer__c; Changes.add(Label+': '+oldBuyer); } opp.WhatChanged__c = CSUtils.join(Changes, ' '); }

It's working, but the part I'm not happy with is the line String fieldName = 'buyer__c'. If the API name for that field ever changes, I will need to update the fieldName variable. Is there a way to dynamically get the API name, in a similar way to how I am getting the field name? Can I create a Map that stores <Field, String>? This is my first time working with Describe.field() methods so I think I'm confusing myself!

 

Any help is much appreciated! Thanks!

  • September 11, 2013
  • Like
  • 0

Hi There,

I have to generate a XML file.

when I click on button button should generate a xml schema file.

 

I am able to create a xml file with the help of  "XmlStreamWriter" class.

 

and able to print in system.debug. but i want to generate xml schema  or what ever I am printing in system debug generate as xml file when i click on button.

 

Example  below xml generate for teh conroller

 

XmlStreamWriter w =newXmlStreamWriter();

w.writeStartDocument(null,'1.0 encoding=UTF-8');

w.writeStartDocument(null,'<soap:Envelope xmlns:soap=http://schemas.xmlsoap.org/soap/envelope/ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">');

w.writeStartElement(null,'Enrol_Event__c ',null);

 

for(Enrol_Event__cenrollEvent : getEnrollmentEventList()){

 

w.writeStartElement('my','LANID','my');

w.writeCharacters('12345678910');

w.writeEndElement();

 w.writeStartElement('my','LegalCompanyName','my');

w.writeCharacters(enrollEvent.PREF_CO_NM__c);

w.writeEndElement();

 w.writeStartElement('my','EnrollmentManagerName','my');

w.writeCharacters(enrollEvent.DSPCH_REP_ID__r.Name);

w.writeEndElement();

 w.writeStartElement('my','ExceptionsSection','my');

 w.writeStartElement('my','ExceptionsDetails','my');

w.writeCharacters(enrollEvent.EXCPT_DET_TXT__c);

w.writeEndElement();

 w.writeStartElement('my','ExceptionsApprovedBy','my');

w.writeCharacters(enrollEvent.EXCPT_APRVD_NM__c);

w.writeEndElement();

 w.writeEndElement();

 

w.writeEndElement();

w.writeEndDocument();

string xml = w.getXmlString();

w.close();

 

system.debug(xml);

 

out put

 

<?xml version="1.0" encoding="UTF-8"?>
<my:myField>
<my:LANID>12345678910</my:LANID>

<my:LegalCompanyName>Preferred Company Name</my:LegalCompanyName>

<my:EnrollmentManagerName>Betsy Barrett</my:EnrollmentManagerName>

<my:ExceptionsSection>

<my:ExceptionsDetails>The cost of the BC is waived for this event.</my:ExceptionsDetails>

<my:ExceptionsApprovedBy>Katie Anderson</my:ExceptionsApprovedBy>

</my:ExceptionsSection>

</my:myField>

 

can any one suggest me how to generate xml schema file or xml file when i click on button.