• himanshu huske 7
  • NEWBIE
  • 85 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 43
    Questions
  • 13
    Replies
public class Claim_Property_from_Sales_Region {

    public contact con {get;set;}
  
    public PageReference Cancel() {
    PageReference prf = new PageReference('https://ap8.salesforce.com/a0H/o');
        return prf;
    }


    public PageReference claimAndCountinue() {
    updateSearchItemsMap();
    SetStatusWorking();
        return null;
    }

    public void SetStatusWorking(){
     List<Property__c> pt = new List<Property__c>();
      set<id> idSet = mapHoldingSelectedRecords.keySet();
     List<Property__c> prplist = [Select id,Status__c from Property__c where id in : idSet];
        for(Property__c prp : prplist){
        Property__c property = new Property__c();
        property.id =  prp.id;
     //   property.Agent__c = UserInfo.getUserId();
        property.Status__c  = 'Working';
        pt.add(property);
        update pt;
        }
}
     
    
    public PageReference claimProp() {
    updateSearchItemsMap();
    SetStatusWorking();
    PageReference pf = new PageReference('https://ap8.salesforce.com/a0H/o');
        return pf;
    }


    public Claim_Property_from_Sales_Region() {
     mapHoldingSelectedRecords = new Map<Id, WrapperClass>();
     init();
    }

   
   Public Integer size{get;set;}
 Public Integer noOfRecords{get; set;}
 public List <WrapperClass> wrapperRecordList{get;set;}
 Map<Id, WrapperClass> mapHoldingSelectedRecords{get;set;}
 
 
 public void init() {
 wrapperRecordList = new List<WrapperClass>();
 for (Property__c p : (List<Property__c>)setCon.getRecords()) {
 if(mapHoldingSelectedRecords != null && mapHoldingSelectedRecords.containsKey(p.id)){
 wrapperRecordList.add(mapHoldingSelectedRecords.get(p.id));
 
 }
 else{
   wrapperRecordList.add(new WrapperClass(p, false));
 }
 }
 } 
 
   public ApexPages.StandardSetController setCon {
 get {
 if(setCon == null) {
   setCon = new ApexPages.StandardSetController(Database.getQueryLocator([SELECT id, Property_Name__c,Property_City__c, Listing_Price__c, Status__c,createdDate FROM Property__c where Status__c = 'open']));
   setCon.setPageSize(5);
 }
   return setCon;
 }
 set;
 }
 public Boolean hasNext {
 get {
   return setCon.getHasNext();
 }
 set;
 }
 
 public Boolean hasPrevious {
 get {
   return setCon.getHasPrevious();
 }
 set;
 }
 
 public Integer pageNumber {
 get {
   return setCon.getPageNumber();
 }
 set;
 }
   Public Integer getTotalPages(){
     Decimal totalSize = setCon.getResultSize();
     Decimal pageSize = setCon.getPageSize();
     Decimal pages = totalSize/pageSize;
     return (Integer)pages.round(System.RoundingMode.CEILING);
 }
 
 public void first() {
   updateSearchItemsMap();
   setCon.first();
   init();
 }
 
 public void last() {
   updateSearchItemsMap();
   setCon.last();
   init();
 }
 public void previous() {
   updateSearchItemsMap();
   setCon.previous();
   init();
 }
 
 public void next() {
   updateSearchItemsMap();
   setCon.next();
   init();
 }

 private void updateSearchItemsMap() {
 for(WrapperClass wrp : wrapperRecordList){
  if(wrp.isSelected){
     mapHoldingSelectedRecords.put(wrp.prop.id, wrp);
  }
  if(wrp.isSelected == false && mapHoldingSelectedRecords.containsKey(wrp.prop.id)){
     mapHoldingSelectedRecords.remove(wrp.prop.id);
  }
 }
 }
 public class WrapperClass {
 public Boolean isSelected {get;set;}
 public Property__c prop {get;set;}
 public WrapperClass(Property__c prop, Boolean isSelected) {
    this.prop = prop;
    this.isSelected = isSelected;
 }
 }
}

 
Objects: Contact and Property_c  
Property__c has Agent__c(lookUp to Contact)
1)   Contact has Default_commission_split__c field and Property has Agent_Commission_Per__c field
Whenever Default_commission_split__c get updated, Agent_Commission_Per__c should also get updated.
2)  Contact has Year_To_date_Total_Sales__c field and Property has Sales_price__c field
Year_To_date_Total_Sales__c should b sum of all Property record Sales_price__c field(Same as rollUp Summary
//trigger
trigger Pupulate_Agent_And_AgentCommission on Property__c (before update,after update) {

    if(trigger.isbefore){
        Populate_Agent_Commision pA = new Populate_Agent_Commision();
        pA.Agent_Commission(trigger.new, trigger.new);
    }
  
    if(trigger.isafter){
        Calculate_YearToSaleDate_From_SalesPrice cY = new Calculate_YearToSaleDate_From_SalesPrice();
        cY.YearToSaleDate_Updation(trigger.new);
    }
}


public class Populate_Agent_Commision {
    public  void Agent_Commission(List<Property__c> prop1,List<Property__c> prop2) {
          list<contact> contactlist = new list<contact>();
   set<id> pset = new set<id>();
       for (Property__c p1 : prop1){
           pset.add(p1.Agent__c);
        }
        map<id,contact> conmap = new map<id,contact>();
   list<contact> conlist = [select id,name,Default_commission_split__c,Year_To_date_Total_Sales__c from contact where id in: pset];
    for(contact c : conlist){
           conmap.put(c.id, c);
    }
    for(property__c p2: prop2){
        if(p2.status__C =='Closed Pending Approval'|| p2.Status__c =='Closed Approved'){
          p2.Agent_Commission_Per__c = conmap.get(p2.Agent__c).Default_commission_split__c;
    
    }
}
}
}

public class Calculate_YearToSaleDate_From_SalesPrice {
    public void YearToSaleDate_Updation(list<Property__c> propList){
        Set<id> AgentId = new Set<id>();
    for(Property__c p1 : propList){
       AgentId.add(p1.Agent__c);
    }
   list<Property__c> pList =  [Select id, Agent__c, Property_Name__c, Sales_price__c From Property__c Where Agent__c IN: AgentId];
    map<Id,list<Property__c>> conMap = new map<Id,list<Property__c>>();
    for(Property__c pr_1 : pList){
       conMap.put(pr_1.Agent__c, new list<Property__c>()); 
       conMap.get(pr_1.Agent__c).add(pr_1);
    }
   list<Contact> conList = [Select id, Name, Year_To_date_Total_Sales__c from Contact Where id IN: conMap.keySet()];
    decimal amount = 0;
    for(Contact c1 : conList){
        for(Property__c pr_2: conMap.get(c1.Id)){
         amount += pr_2.Sales_price__c;  
        }
       c1.Year_To_date_Total_Sales__c = amount;
    }    
   update conList;
    }
}

)



 
trigger Trg_Property_Contact on Property__c (before update,after update) {
   String UserID = UserInfo.getUserId();
   list<contact> contactlist = new list<contact>();
   set<id> pset = new set<id>();
   map<id,contact> conmap = new map<id,Contact>();
       for (Property__c p : trigger.new){
           pset.add(p.Agent__c);
        }
   list<contact> conlist = [select id,name,Default_commission_split__c,Year_To_date_Total_Sales__c from contact where id in: pset];
    for(contact c : conlist){
           conmap.put(c.id, c);
    }
if(trigger.isbefore){
    for(property__c p1: trigger.new){
        if(p1.status__C =='Closed Pending Approval'|| p1.Status__c =='Closed Approved'){
          p1.Agent_Commission_Per__c = conmap.get(p1.Agent__c).Default_commission_split__c;
    }
}
   
}
if(trigger.isafter){
      set<id> myset = new set<id>();
      map<id,contact> cmap = new map<id,Contact>();
      list<contact> contactlist = new list<contact>();
          for (Property__c p : trigger.old){
               myset.add(p.Agent__c);
          }
   list<contact> conlist = [select id,name,Default_commission_split__c,Year_To_date_Total_Sales__c from contact where id in: myset];
       for(contact ct : conlist){
           cmap.put(ct.id, ct);
          }
       for(property__c p3: trigger.old){
        if(p3.status__C =='Closed Pending Approval'){
            if(cmap.containskey(p3.Agent__c)){
               contact c1 = cmap.get(p3.Agent__c); 
               c1.Year_To_date_Total_Sales__c = c1.Year_To_date_Total_Sales__c + p3.Sales_price__c;
            }
    }
  }
    update contactlist;
}
}

 
There are two Objects:
1.Property__c(obj) with fields Status__c(Picklist) and Ajent__c(lookUp to Contact)
2.Contact (obj)
Scenerio:
Contact obj has some records 
if user change status__c of property form 'open' to 'working' the, If that user have a contact record, Agent__c field should get populated with that Contact Name field.  
this page i wanna create, please correct the  codeUser-added image
 
<apex:page standardController="Sales_Office__c"  docType="html-5.0" tabStyle="Sales_Office__c" extensions="Claim_Property_from_Sales_Region" recordSetVar="wrapperRecordList">
  <apex:sectionHeader title="Sales Office" subtitle="{!Sales_Office__c.Sales_Office_Name__c}" />
   <apex:form title="{!Sales_Office__c.Sales_Office_Name__c}"> 
   <apex:pageBlock title="Sales Office" rendered="{!wrapperRecordList.size!=0}" id="pbId" >
   <apex:commandButton label="Calim Property" value={!claimProp}/>>
    <apex:commandButton label="Calim and countinue" value={!claimAndCountinue}/>>
     <apex:commandButton label="Cancel" value={!Cancel}/>>
    <apex:pageBlockTable value="{!wrapperRecordList}" var="cont">
           <apex:column headerValue="Select">
             <apex:inputCheckbox value="{!p.isSelected}"/>
           </apex:column>
           <apex:column headerValue="Property">
             <apex:outputField value="{!p.prop.Property_Name__c}"/>
           </apex:column>
           <apex:column headerValue="Property City">
             <apex:outputField value="{!p.prop.Property_City__c}"/>
           </apex:column>
           <apex:column headerValue="List Price">
            <apex:outputField value="{!p.pop.Listing_Price__c}"/>
           </apex:column>
           <apex:column headerValue="Status">
            <apex:outputField value="{!p.pop.Status__c}"/>
           </apex:column>
           <apex:column headerValue="Date Added">
            <apex:outputField value="{!p.pop.createdDate}"/>
           </apex:column>
       </apex:pageBlockTable>       
    <apex:outputPanel style="text-align:center;" layout="block">
          <apex:commandButton value="First" reRender="pbId" action="{!first}" disabled="{!NOT(hasPrevious)}" status="paginationStatus"/>
          <apex:commandButton value="Previous" rerender="pbId" action="{!previous}" disabled="{!NOT(hasPrevious)}" status="paginationStatus"/>&nbsp;Page {!pageNumber} of {!totalPages}&nbsp;
          <apex:commandButton value="Next" rerender="pbId" action="{!next}" disabled="{!NOT(hasNext)}" status="paginationStatus"/>
          <apex:commandButton value="Last" rerender="pbId" action="{!last}" disabled="{!NOT(hasNext)}" status="paginationStatus"/>
          <apex:actionStatus id="paginationStatus">
             <apex:facet name="start">
                 Please wait...<img src="/img/loading32.gif" style="width: 18px;"/>
             </apex:facet>
          </apex:actionStatus>
          </apex:outputPanel>
     </apex:pageBlock>
   </apex:form>
</apex:page>



public class Claim_Property_from_Sales_Region {
   
   Public Integer size{get;set;}
 Public Integer noOfRecords{get; set;}
 public List<SelectOption> paginationSizeOptions{get;set;}
 public static final Integer QUERY_LIMIT = 10000;
 public static final Integer PAGE_SIZE = 5;
 public List <WrapperClass> wrapperRecordList{get;set;}
 Map<Id, WrapperClass> mapHoldingSelectedRecords{get;set;}
 
 public Claim_Property_from_Sales_Region (ApexPages.StandardSetController con){
 }
 
 public Claim_Property_from_Sales_Region(){
   mapHoldingSelectedRecords = new Map<Id, WrapperClass>();
   init();

//Init method which queries the records from standard set controller.
 public void init() {
 wrapperRecordList = new List<WrapperClass>();
 for (Property__c p : (List<Property__c>)setCon.getRecords()) {
 if(mapHoldingSelectedRecords != null && mapHoldingSelectedRecords.containsKey(p.id)){
 wrapperRecordList.add(mapHoldingSelectedRecords.get(p.id));
 
 }
 else{
   wrapperRecordList.add(new WrapperClass(p, false));
 }
 }
 } 
 
   /** Instantiate the StandardSetController from a query locater*/  
   public ApexPages.StandardSetController setCon {
 get {
 if(setCon == null) {
   setCon = new ApexPages.StandardSetController(Database.getQueryLocator([SELECT Property_Name__c,Property_City__c, Listing_Price__c, Status__c,createdDate FROM Property__c where Status__c = 'open' LIMIT : QUERY_LIMIT ]));
 // sets the number of records to show in each page view
   setCon.setPageSize(PAGE_SIZE);
 }
   return setCon;
 }
 set;
 }
 public Boolean hasNext {
 get {
   return setCon.getHasNext();
 }
 set;
 }
 
 /** indicates whether there are more records before the current page set.*/
 public Boolean hasPrevious {
 get {
   return setCon.getHasPrevious();
 }
 set;
 }
 
 /** returns the page number of the current page set*/
 public Integer pageNumber {
 get {
   return setCon.getPageNumber();
 }
 set;
 }
 /** return total number of pages for page set*/
   Public Integer getTotalPages(){
     Decimal totalSize = setCon.getResultSize();
     Decimal pageSize = setCon.getPageSize();
     Decimal pages = totalSize/pageSize;
     return (Integer)pages.round(System.RoundingMode.CEILING);
 }
 
 /** returns the first page of the page set*/
 public void first() {
   updateSearchItemsMap();
   setCon.first();
   init();
 }
 
 /** returns the last page of the page set*/
 public void last() {
   updateSearchItemsMap();
   setCon.last();
   init();
 }
 /** returns the previous page of the page set*/
 public void previous() {
   updateSearchItemsMap();
   setCon.previous();
   init();
 }
 
 /** returns the next page of the page set*/
 public void next() {
   updateSearchItemsMap();
   setCon.next();
   init();
 }
 //This is the method which manages to remove the deselected records, and keep the records which are selected in map.
 private void updateSearchItemsMap() {
 for(WrapperClass wrp : wrapperRecordList){
  if(wrp.isSelected){
     mapHoldingSelectedRecords.put(wrp.prop.id, wrp);
  }
  if(wrp.isSelected == false && mapHoldingSelectedRecords.containsKey(wrp.prop.id)){
     mapHoldingSelectedRecords.remove(wrp.prop.id);
  }
 }
 }
 public class WrapperClass {
 public Boolean isSelected {get;set;}
 public Property__c prop {get;set;}
 public WrapperClass(Property__c prop, Boolean isSelected) {
    this.prop = prop;
    this.isSelected = isSelected;
 }
 }
}



 
I Have Object : Country__c  With Fields: Name__c,Capital_City__c,Region__c,Sub_Region__c,
Regional_Block__c 
Country__c object  has records of various countries
And in Lead Object I have Fields Country_1__c,Region__c,Capital_City__c,Sub_Region__c,Regional_Block__c
Whenever we insert/update any country name in lead Country_1__c field which exist in Country__c(object) record field  Name__c
then populate all lead fields
trigger countryInfoUpdate on Lead (before insert, before update) {
 //List<Lead> lList = new List<Lead>();  
  Set<String> strSet = new Set<String>();
    for(Lead l : trigger.new){
    strSet.add(l.Country_1__c); 
    }
    List<Country__c> conList = [Select id,Name__c,Capital_City__c,Region__c,Sub_Region__c,
                                Regional_Block__c from Country__c Where Name__c in: strSet];
    map<String,Country__c>  conMap = new   map<String,Country__c>();
    for(Country__c c : conlist){
        conMap.put(c.Name__c, c);
    }
    for(Lead l : trigger.new){
        if(conMap.containsKey(l.Country_1__c)){
          l.Region__c = conmap.get(l.Country_1__c).Region__c;
          l.Capital_City__c = conmap.get(l.Country_1__c).Capital_City__c;
          l.Sub_Region__c = conmap.get(l.Country_1__c).Sub_Region__c;
          l.Regional_Block__c = conmap.get(l.Country_1__c).Regional_Block__c;
        }
    } 
}





 
Hi mighty developers,
I m a beginner, please correct my code.
i have Country__c Object with all Text fields  Name__c,Capital_City__c,Region__c,Sub_Region__c,Regional_Block__c,Country_ISO_Code_2__c,Country_ISO_Code_3__c from Country__c.
this is the Url for integration:  https://restcountries.eu/
I want to create records for each country and populate all fiels in records for JSON
also provide testing code if possible
public class CountryNameWrapper{
	public string name{get;set;}
	public string alpha2Code{get;set;}
	public string alpha3Code{get;set;}
	public string capital{get;set;}
	public string region{get;set;}
	public string subregion{get;set;}
	public List<CountryNameWrapper.RegionalBlocsWrapper> regionalBlocs{get;set;}
	
	public class RegionalBlocsWrapper{
		public String acronym{get;set;}
		public String name{get;set;}
		public List<String> otherAcronyms{get;set;}
		public List<String> otherNames{get;set;}
	}
}


global class Load_Countries_RestApi implements Database.Batchable<sObject>,Database.AllowsCallouts {
 global String query ;
    
 global Database.QueryLocator start(Database.BatchableContext BC) {
     query = 'Select Name__c,Capital_City__c,Region__c,Sub_Region__c,Country_ISO_Code_2__c,Country_ISO_Code_3__c from Country__c';     
        //Query all countries from Country object
        return DataBase.getQueryLocator(query);                                    
    }
    
 global void execute(Database.BatchableContext BC , List <Country__c> contlist) {
     Boolean hasChanged = false;
     Http http = new Http();
     HttpRequest request = new HttpRequest();
     request.setEndpoint('https://restcountries.eu/rest/v2/all');
     request.setMethod('GET');
     HttpResponse response = http.send(request);
     if (response.getStatusCode() == 299) {
     System.debug('response--->'+(List<CountryNameWrapper>)JSON.deserialize(response.getBody(),List<CountryNameWrapper>.class));
     List<CountryNameWrapper> abc = (List<CountryNameWrapper>)JSON.deserialize(response.getBody(),List<CountryNameWrapper>.class);
     List<Country__c> cntList = new List<Country__c>();
     for(CountryNameWrapper cw : abc){
     Country__c cnt = new Country__c();
     cnt.Name__c = cw.name;
     cnt.Capital_City__c = cw.name;
     cnt.Region__c = cw.region;
     cnt.Sub_Region__c = cw.subregion;
  //   cnt.Regional_Block__c = cw.regionalBlocs;
     cnt.Country_ISO_Code_2__c = cw.alpha2Code;
     cnt.Country_ISO_Code_3__c = cw.alpha3Code;
     cntList.add(cnt);
}
insert cntList;
     //Give call to https://restcountries.eu/rest/v2/name/AF
     //AF is country name. It will return you the iterate over the list //(List<CountryNameWrapper>) and see if the information in country is same //as that of object returned from API. If it is not same then set boolean
     //hasChanged to true.
     
     //If has changed is true, then update country object
     }    
 }
 global void finish(Database.BatchableContext BC){
 }   
}

 
Hi developers,
I m a beginner, please correct my code.
i have Country__c Object with all Text fields  Name__c,Capital_City__c,Region__c,Sub_Region__c,Regional_Block__c,Country_ISO_Code_2__c,Country_ISO_Code_3__c from Country__c.
this is the Url for integration:  https://restcountries.eu/
I want to create records for each country and populate all fiels in records for JSON
also provide testing code if possible
public class CountryNameWrapper{
	public string name{get;set;}
	public string alpha2Code{get;set;}
	public string alpha3Code{get;set;}
	public string capital{get;set;}
	public string region{get;set;}
	public string subregion{get;set;}
	public List<CountryNameWrapper.RegionalBlocsWrapper> regionalBlocs{get;set;}
	
	public class RegionalBlocsWrapper{
		public String acronym{get;set;}
		public String name{get;set;}
		public List<String> otherAcronyms{get;set;}
		public List<String> otherNames{get;set;}
	}
}


global class Load_Countries_RestApi implements Database.Batchable<sObject>,Database.AllowsCallouts {
 global String query ;
    
 global Database.QueryLocator start(Database.BatchableContext BC) {
     query = 'Select Name__c,Capital_City__c,Region__c,Sub_Region__c,Country_ISO_Code_2__c,Country_ISO_Code_3__c from Country__c';     
        //Query all countries from Country object
        return DataBase.getQueryLocator(query);                                    
    }
    
 global void execute(Database.BatchableContext BC , List <Country__c> contlist) {
     Boolean hasChanged = false;
     Http http = new Http();
     HttpRequest request = new HttpRequest();
     request.setEndpoint('https://restcountries.eu/rest/v2/all');
     request.setMethod('GET');
     HttpResponse response = http.send(request);
     if (response.getStatusCode() == 299) {
     System.debug('response--->'+(List<CountryNameWrapper>)JSON.deserialize(response.getBody(),List<CountryNameWrapper>.class));
     List<CountryNameWrapper> abc = (List<CountryNameWrapper>)JSON.deserialize(response.getBody(),List<CountryNameWrapper>.class);
     List<Country__c> cntList = new List<Country__c>();
     for(CountryNameWrapper cw : abc){
     Country__c cnt = new Country__c();
     cnt.Name__c = cw.name;
     cnt.Capital_City__c = cw.name;
     cnt.Region__c = cw.region;
     cnt.Sub_Region__c = cw.subregion;
  //   cnt.Regional_Block__c = cw.regionalBlocs;
     cnt.Country_ISO_Code_2__c = cw.alpha2Code;
     cnt.Country_ISO_Code_3__c = cw.alpha3Code;
     cntList.add(cnt);
}
insert cntList;
     //Give call to https://restcountries.eu/rest/v2/name/AF
     //AF is country name. It will return you the iterate over the list //(List<CountryNameWrapper>) and see if the information in country is same //as that of object returned from API. If it is not same then set boolean
     //hasChanged to true.
     
     //If has changed is true, then update country object
     }    
 }
 global void finish(Database.BatchableContext BC){
 }   
}

 
Hi mighty developers,
Please help me with code,
I have custom Object : country
with fields (all text fields) :  Name,Capital City, Country ISO Code 2, Country ISO Code 3,  Region,  Regional Block, Sub Region.
URL : https://restcountries.eu/
Given Below is Url from where i have retrive information of all countries in above 'Country' object for respective field.
Please give me code for Batch Apex Callout for above scenerio
 
In Account object there is a checkbox IsPrimary__c, and in Contact there is PickList Status__c(values: 'IsPrimary', 'IsSecondery').
for an account record if two contact record are created with one as Status__c = IsPrimary and another Status__c = IsSecondery.
1. If in Account IsPrimary__c checkbox is checked then.
Account Discription = Discription in contact having Status__c = IsPrimary. 
2. If in Account IsPrimary__c checkbox is Unchecked then.
Account Discription = Discription in contact having Status__c = IsSecondery.
Please Provide Trigger Using Map
please correct my code below,
  I have one object Customer__c,In this there are one  picklist User_to_b__c.
if valid userName is input in User_to_b__c field. owner field should update with value in User_to_b__c
trigger Cust_User_to_be on Customer__c (before insert, before update) {
     Set<string> strSet = new Set<String>();
      for(Customer__c cs : trigger.new)
      {
              strSet.add(cs.User_to_b__c);
       }
    map<string,id> csMap = new map<string,id>();  
    for(User u : [Select id,Name from user where Name IN :strSet])
    {
            csMap.put(u.Name,u.Id);
     }
    for (Customer__c cs : Trigger.new)
    {
             if (cs.OwnerId <> csMap.get(cs.User_to_b__c) )          
             {
                   cs.OwnerId = csMap.get(cs.User_to_b__c);
              }

    }
}

 
Hi guys help me out with some concept,
I learnt Set, Map and all their releted methods.
but while writing triggers I cannot decide when to use Map and Set,
please tell me how to decide, while writing, now their is need of Map.
I Have customer obj with field IsPrimary(checkbox) and addrText(textarea)
I also have an obj Addresses with field Addr_type(picklist with valuse 'Primery' and 'Secondery') and Addr_Line_1
if IspPrimary is checked, addrText should get populated with Addresses record Addr_Line_1 having  having picklist value as primary 
else adresses record with secondery value of addressLine_1
I want to create Visualforce Page in which their is a timer for Hour,Minute,Seconds which should start when we click on 'START' button and stop When 'STOP' button is clicked
I have customer__c object with FirstName_c, LastName_c, DOB_c fields.
First VF page has  FirstName_c, LastName_c, DOB_c  InputFields and a "save" button which save record in Object
And "List" Button show that record fields with that values of input field in Second VF page.
 
Please explain me soql subQuery.
when and how to use it in Apex Code(triggers) ?
in Map and in List
give me some examples

Hi developers,
Please fix th issue for thisUser-added imagetrigger TotalAmt_Child_paraent on Child__c (after insert,after update, after delete,after undelete) {
    set<id> idSet = new  set<id>();
    List<Child__c> cList = new List<Child__c>();
    List<Parent__c> pList = new List<Parent__c>();
    if(trigger.isinsert ||trigger.isupdate ||trigger.isundelete){
        for(Child__c c : trigger.new){
            if(c.ParentMD__c != null)
                idSet.add(c.ParentMD__c);
        }
    }
    if(trigger.isdelete){
        for(Child__c c : trigger.old){
            if(c.ParentMD__c != null)
                idSet.add(c.ParentMD__c);
        }
    }    
    if(idSet.size()>0){
    decimal amt = 0;
    cList = [Select id, ParentMD__c from Child__c where ParentMD__c in: idSet];
    Map<id,List<Child__c>> prMap = new Map<id,List<Child__c>>();
    for(Child__c c : cList){
        prMap.put(c.ParentMD__c, new List<Child__c>());
        prMap.get(c.ParentMD__c).add(c);
    }
    pList = [Select id,TotalAmt__c from Parent__c where id in: prMap.keySet()];
        for(Parent__c p : pList){
            for(Child__c ch : prMap.get(p.id)){
                if(ch.MyAmt__c != null)
                    amt +=  ch.MyAmt__c; 
            }
            p.TotalAmt__c = amt;
        }
        update pList;
    }
    }
Both Account and Contact has a picklist field Status_c with values Open,Close,InProgress 
account record has 3 child record in contact
if all 3 contact has picklist value = 'close', then account picklist value will get updated to 'close'.
I have customer__c object with FirstName_c, LastName_c, DOB_c fields.
First VF page shows  FirstName_c, LastName_c, DOB_c  in cloumn view.
FirstName_c is in commandLink, if we click on any of  FirstName_c in column, its record should be displayed in 2nd VF page. 
In case object there is one custom text field type_c
case has record with any subject, and if we create another record with same subject, type_c field should be populated as 'duplicate'.
and this newly created case should b displayed in related list of previus case record.
There are two Objects:
1.Property__c(obj) with fields Status__c(Picklist) and Ajent__c(lookUp to Contact)
2.Contact (obj)
Scenerio:
Contact obj has some records 
if user change status__c of property form 'open' to 'working' the, If that user have a contact record, Agent__c field should get populated with that Contact Name field.  
Hi mighty developers,
I m a beginner, please correct my code.
i have Country__c Object with all Text fields  Name__c,Capital_City__c,Region__c,Sub_Region__c,Regional_Block__c,Country_ISO_Code_2__c,Country_ISO_Code_3__c from Country__c.
this is the Url for integration:  https://restcountries.eu/
I want to create records for each country and populate all fiels in records for JSON
also provide testing code if possible
public class CountryNameWrapper{
	public string name{get;set;}
	public string alpha2Code{get;set;}
	public string alpha3Code{get;set;}
	public string capital{get;set;}
	public string region{get;set;}
	public string subregion{get;set;}
	public List<CountryNameWrapper.RegionalBlocsWrapper> regionalBlocs{get;set;}
	
	public class RegionalBlocsWrapper{
		public String acronym{get;set;}
		public String name{get;set;}
		public List<String> otherAcronyms{get;set;}
		public List<String> otherNames{get;set;}
	}
}


global class Load_Countries_RestApi implements Database.Batchable<sObject>,Database.AllowsCallouts {
 global String query ;
    
 global Database.QueryLocator start(Database.BatchableContext BC) {
     query = 'Select Name__c,Capital_City__c,Region__c,Sub_Region__c,Country_ISO_Code_2__c,Country_ISO_Code_3__c from Country__c';     
        //Query all countries from Country object
        return DataBase.getQueryLocator(query);                                    
    }
    
 global void execute(Database.BatchableContext BC , List <Country__c> contlist) {
     Boolean hasChanged = false;
     Http http = new Http();
     HttpRequest request = new HttpRequest();
     request.setEndpoint('https://restcountries.eu/rest/v2/all');
     request.setMethod('GET');
     HttpResponse response = http.send(request);
     if (response.getStatusCode() == 299) {
     System.debug('response--->'+(List<CountryNameWrapper>)JSON.deserialize(response.getBody(),List<CountryNameWrapper>.class));
     List<CountryNameWrapper> abc = (List<CountryNameWrapper>)JSON.deserialize(response.getBody(),List<CountryNameWrapper>.class);
     List<Country__c> cntList = new List<Country__c>();
     for(CountryNameWrapper cw : abc){
     Country__c cnt = new Country__c();
     cnt.Name__c = cw.name;
     cnt.Capital_City__c = cw.name;
     cnt.Region__c = cw.region;
     cnt.Sub_Region__c = cw.subregion;
  //   cnt.Regional_Block__c = cw.regionalBlocs;
     cnt.Country_ISO_Code_2__c = cw.alpha2Code;
     cnt.Country_ISO_Code_3__c = cw.alpha3Code;
     cntList.add(cnt);
}
insert cntList;
     //Give call to https://restcountries.eu/rest/v2/name/AF
     //AF is country name. It will return you the iterate over the list //(List<CountryNameWrapper>) and see if the information in country is same //as that of object returned from API. If it is not same then set boolean
     //hasChanged to true.
     
     //If has changed is true, then update country object
     }    
 }
 global void finish(Database.BatchableContext BC){
 }   
}

 
In Account object there is a checkbox IsPrimary__c, and in Contact there is PickList Status__c(values: 'IsPrimary', 'IsSecondery').
for an account record if two contact record are created with one as Status__c = IsPrimary and another Status__c = IsSecondery.
1. If in Account IsPrimary__c checkbox is checked then.
Account Discription = Discription in contact having Status__c = IsPrimary. 
2. If in Account IsPrimary__c checkbox is Unchecked then.
Account Discription = Discription in contact having Status__c = IsSecondery.
Please Provide Trigger Using Map
I Have customer obj with field IsPrimary(checkbox) and addrText(textarea)
I also have an obj Addresses with field Addr_type(picklist with valuse 'Primery' and 'Secondery') and Addr_Line_1
if IspPrimary is checked, addrText should get populated with Addresses record Addr_Line_1 having  having picklist value as primary 
else adresses record with secondery value of addressLine_1
I want to create Visualforce Page in which their is a timer for Hour,Minute,Seconds which should start when we click on 'START' button and stop When 'STOP' button is clicked
Account and Contact One Custom fiedl - "Status"
one Account having multiple contact - if all contact Status fiedl is Active then only update "Active" in Account page. Even if 1 contact inactive then Account also inactive - 
I have written trigger. but it working fine only with 1 record. I mean when user insert new contatc at that whatever status I have given based on that it update on contact. but how to check for All contact ? 
I have customer__c object with FirstName_c, LastName_c, DOB_c fields.
First VF page has  FirstName_c, LastName_c, DOB_c  InputFields and a "save" button which save record in Object
And "List" Button show that record fields with that values of input field in Second VF page.
 

Hi developers,
Please fix th issue for thisUser-added imagetrigger TotalAmt_Child_paraent on Child__c (after insert,after update, after delete,after undelete) {
    set<id> idSet = new  set<id>();
    List<Child__c> cList = new List<Child__c>();
    List<Parent__c> pList = new List<Parent__c>();
    if(trigger.isinsert ||trigger.isupdate ||trigger.isundelete){
        for(Child__c c : trigger.new){
            if(c.ParentMD__c != null)
                idSet.add(c.ParentMD__c);
        }
    }
    if(trigger.isdelete){
        for(Child__c c : trigger.old){
            if(c.ParentMD__c != null)
                idSet.add(c.ParentMD__c);
        }
    }    
    if(idSet.size()>0){
    decimal amt = 0;
    cList = [Select id, ParentMD__c from Child__c where ParentMD__c in: idSet];
    Map<id,List<Child__c>> prMap = new Map<id,List<Child__c>>();
    for(Child__c c : cList){
        prMap.put(c.ParentMD__c, new List<Child__c>());
        prMap.get(c.ParentMD__c).add(c);
    }
    pList = [Select id,TotalAmt__c from Parent__c where id in: prMap.keySet()];
        for(Parent__c p : pList){
            for(Child__c ch : prMap.get(p.id)){
                if(ch.MyAmt__c != null)
                    amt +=  ch.MyAmt__c; 
            }
            p.TotalAmt__c = amt;
        }
        update pList;
    }
    }
Write a trigger to auto calculate sum of amount when ever record is inserted update deleted in opportunity object using rollup summary fields
1.customer__c(master obj) and address__c(detail obj).
address__c has has 2 checkbox field Nagpur__c and Pune__c and customer__c has TextField Hometown__c 
if Nagpur__c is checked, Hometown__c = 'nagpur';
if Pune__c is checked, Hometown__c = 'pune';
2. is it true, that master-detail relation trigger like above wont require query ?
 
Please Help Me With Code.
I want to create a page in which,
we use <apex:inputField> or <apex:inputText> for FirstName, LastName, DateOfBirth,Gender(PickList).
There will be a button on page, after insert value in each field and clicking on button, next page will get display, wich will show list of output. which we have entered in inputField or input text.
please give me a code using following methods,
PageReference Px = page.PageName;
    Px.getParameters().put();
ApexPages.currentPage().getParameters().get();
 
help me with trigger code.
An object has FirstName and LastName field, if we try to create a record with same FristName and LastName, record should not create(throws error).
 
Whenever a new transaction is performed successfully then update the customer object balance field based on 
     If Transaction Type=Deposit, Balance= balance +amount ;  withdraw balance= balance-amount;
     Note: Customers and Transaction has lookup Detail Relation.