You need to sign in to do that
Don't have an account?
Satish Prajapat
How to insert/update Map<String, String> into Account
I have Map<String, String> m1 = ........;/(Map Contain only one record information)
And I want to update the record into account How can I do this?
And I want to update the record into account How can I do this?
Your post is helpful if we make some changes:
But there is a problem to update non-editable fields.
Please help me to update the record...!!!!
All Answers
Please find the sample code for updating a related record with a Map. Hope this helps.
Please mark this as solved if it's resolved so that it gets removed from the unanswered queue which results in helping others who are encountering a similar issue.
Thanks,
Nagendra
Hello Nagendra,
This code is not helping to solve my doubt because second for loop is getting the value from Trigger.New which is sObject Type(Customer_Product_Line_Item__c Object) and in the line number 19
<<<cpli.Strategic_Industry__c = imap.get( cpli.Industry_Segment__c );>>>
cpli.Industry_Segment__c is confusing because the imap contain the only two field which is not it.
So, This is not helpful for me.
their are more than 50 fields,
Object is Account Object,
Map contain the single record:
{accountnumber=null, accountsource=null, active__c=null, annualrevenue=null, billingaddress=null, billingcity=null, billingcountry=null, billinggeocodeaccuracy=null, billinglatitude=null, billinglongitude=null, ...}
if it is only one record the how is the MAP structured ? If it carry record ID and record detail then you can use map.keyset() for record ID and map.values() for record details then you can associate the ID to account object and udate it directly
Map<String,String> map_Account // contains record ID and record details
Account acc = map_Account.values();
acc.id = map_Account.keyset();
update acc;
Thanks ,
Sagarika
Account acc = map_Account.values(); //Error -->Illegal assignment from List<String> to Account
acc.id = map_Account.keyset(); //Error --> Illegal assignment from Set<String> to Id
It is not working....
Hello All,
Can we do like this?
List<Account> myList = new List<Account>();
Account acc_Object = new Account();
for(String Field_API_Name: m1.keySet())
{
acc_Object.Field_API_Name = m1.get(Field_API_Name); // Getting error --->>Variable does not exist: Field_API_Name
}
myList.add(acc_Object);
update myList;
Is it possible do this????????
Account acc_Object = new Account();
SObject sobj = acc_Object;
for(String Field_API_Name: m1.keySet())
{
sobj.get(Field_API_Name) = m1.get(Field_API_Name);
}
Account update_Acc = (Account)sobj;
//As only single record , so no list required .
//myList.add(acc_Object);
update update_Acc;
I think above will work.
if you are getting map<string,string> , then i think you can simply assign the value using get method
Account acc = new Account();
acc.name = m1.get('name');
acc.Id = m1.get('Id');
but in this case you need to put all field name with case sensitive as per it defined in the map . It maynot recomended but it may solve your problem.
Your post is helpful if we make some changes:
But there is a problem to update non-editable fields.
Please help me to update the record...!!!!