• sultan
  • SMARTIE
  • 824 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 3
    Likes Received
  • 0
    Likes Given
  • 147
    Questions
  • 37
    Replies
public class gh {
   
    public string aname {set;get;}
    public string aphone {set;get;}
    public string acity {set;get;}
   // public string createddate{set;get;}
    public list<account> arecs {set;get;}
    public list<lead> lrecs {set;get;}
   // public list<uids__c> urecs {set;get;}
   
   
   
    public void mups(){
       
     list<account> ls =  [select id,name,phone,billingcity
                          from account where name = :aname];
       
        if ( ls.size() == 0){
            account ac = new account();
                ac.name = aname;
                ac.phone = aphone;
                ac.BillingCity = acity;
            upsert ac;        // it works insert
           
            apexpages.Message msg1 = new apexpages.Message
                        (apexpages.Severity.CONFIRM, aname + ' Record Inserted Successfully');
            apexpages.addMessage(msg1);
        }
        else {
           
            for(account ac : ls){    // for(integer i=1; i<ls.size(); i++)
                ac.phone = aphone;
                ac.BillingCity = acity;
              upsert ac;      // as record id exists, works as Update                     
            }

            apexpages.Message msg2 = new apexpages.Message
                        (apexpages.Severity.WARNING, ls.size() + ' Records Updated Successfully');
            apexpages.addMessage(msg2);
        }
           
        arecs = [select id,name,phone,billingcity, createddate
                 from account where name =:aname];
    }
    public void mups{
        list<lead> ls1=[select id,name,phone from lead where name=:aname];
        if(ls1.size()==0){
            lead ac=new lead();
            ac.name=aname;
            ac.Phone=aphone;
            upsert ac;
            apexpages.Message msg3 = new apexpages.Message
                        (apexpages.Severity.CONFIRM, aname + ' Record Inserted Successfully');
            apexpages.addMessage(msg3);
           }
            else{
                for(lead ac : ls){}
                    ac.Name=aname;
                ac.Phone=aphone;
                upsert ac;
            }
         apexpages.Message msg4 = new apexpages.Message
                        (apexpages.Severity.WARNING, ls.size() + ' Records Updated Successfully');
            apexpages.addMessage(msg4);
    }
         lrecs=[select id,name,phone from lead where name=:aname];
    }
    public void mf(){
       
       // list<account> ls =      [slect id from account];

        list<list<account>> ls =         [ find :aname in all fields
                                        returning
                         account(id,name,phone,billingcity,createddate),
                    lead(id,name,phone,createddate)];
       
        arecs = ls[0];
    //lrecs =    ls[1];
       // urecs =    ls[2];
    }
   
   
}
  • August 16, 2014
  • Like
  • 0

list<account> alist=[select  count(name) from account where name like 'T%'];
for(account a:alist)
{
    system.debug('Records are:'+a);
}
  • August 16, 2014
  • Like
  • 0
Trigger updatecontact on Account(after insert,after update)
{
set<id> set1=new set<id>();
list<contact> aconlist=new list<contact>();
for(account a:Trigger.new)
{
set1.add(a.id);
}
list<contact> conlist=[select id,name,accountid from contact where accountid in:set1];

for(account d:Trigger.new)
{
for(contact c:conlist)
{
if(d.id==c.accountid)
{
d.industry=c.department;
aconlist.add(c);
}
}
}
update aconlist;
}
  • August 15, 2014
  • Like
  • 0
We have Account,Contact & Oppurtunity objects in the VF pages.
As iam trying on Account object, in the Account name field if i enter my name (XXX) the moment the mouse down,
below the details should be automatically populated in the Contacts and Oppurtunities.